Create a folder and sub folder in Excel VBA

后端 未结 13 1452
梦谈多话
梦谈多话 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:21

    Here's short sub without error handling that creates subdirectories:

    Public Function CreateSubDirs(ByVal vstrPath As String)
       Dim marrPath() As String
       Dim mint As Integer
    
       marrPath = Split(vstrPath, "\")
       vstrPath = marrPath(0) & "\"
    
       For mint = 1 To UBound(marrPath) 'walk down directory tree until not exists
          If (Dir(vstrPath, vbDirectory) = "") Then Exit For
          vstrPath = vstrPath & marrPath(mint) & "\"
       Next mint
    
       MkDir vstrPath
    
       For mint = mint To UBound(marrPath) 'create directories
          vstrPath = vstrPath & marrPath(mint) & "\"
          MkDir vstrPath
       Next mint
    End Function
    
    0 讨论(0)
提交回复
热议问题