Create a folder and sub folder in Excel VBA

后端 未结 13 1585
梦谈多话
梦谈多话 2020-11-28 05:43

I have a pull down menu of companies that is populated by a list on another sheet. Three columns, Company, Job #, and Part Number.

When a job is created I need a fo

13条回答
  •  再見小時候
    2020-11-28 06:09

    For those looking for a cross-platform way that works on both Windows and Mac, the following works:

    Sub CreateDir(strPath As String)
        Dim elm As Variant
        Dim strCheckPath As String
    
        strCheckPath = ""
        For Each elm In Split(strPath, Application.PathSeparator)
            strCheckPath = strCheckPath & elm & Application.PathSeparator
            If (Len(strCheckPath) > 1 And Not FolderExists(strCheckPath)) Then
                MkDir strCheckPath
            End If
        Next
    End Sub
    
    Function FolderExists(FolderPath As String) As Boolean
         FolderExists = True
         On Error Resume Next
         ChDir FolderPath
         If Err <> 0 Then FolderExists = False
         On Error GoTo 0
    End Function
    

提交回复
热议问题