如何添加文件夹

时间:2021-08-02 00:31:35

标签: excel vba

好的,我有一个代码脚本。当我在模块 19 中运行它时,我得到 "Run-Time Error 76" "Path not Found" 。但在我的模块 18 中,代码运行良好,但对不同的单元格感到兴奋。

Sub Customer_Save()
    ' 302

    Dim Tmp         As String
    Dim FldName     As String
    
    ' 1. Create the name you want to search for before starting the search
    ' 2. don't refer to cells by their range names (too cumbersome)
    FldName = ActiveWorkbook.Sheets("CUSTOMER INFO").Cells(3, 1).Text                          ' actually, it's Cells(3, 1)
    Debug.Print FldName                                     ' check the name
    If Len(FldName) Then
        Tmp = ActiveWorkbook.Sheets("CUSTOMER INFO").Cells(3, 7).Text
        If Len(Tmp) Then
            FldName = Tmp & "\" & FldName                   ' observe how to add the path separator
            Debug.Print FldName                             ' check the name
            FldName = ActiveWorkbook.path & "\CUSTOMER HISTORY\" & FldName
            Debug.Print FldName                                 ' check the name
            
            If Dir(FldName) = vbNullString Then MkDir FldName
        Else
            MsgBox "Cell G3 is blank"
        End If
    Else
        MsgBox "Cell A3 is blank"
    End If
    
End Sub
 

0 个答案:

没有答案