VBA - Do While Loop returns Dir

前端 未结 2 1284
北荒
北荒 2020-12-12 06:40

I am running a loop through a folder in order to get the complete filename address (folders address + file name and extension).

I am using the following, but at some

相关标签:
2条回答
  • 2020-12-12 07:07

    Instead of DIR, how about this:

    ' enable Tools->References, Microsoft Scripting Runtime
    
    Sub Test()
        Dim fso As New Scripting.FileSystemObject
        Dim fldr As Folder
    
        Set fldr = fso.GetFolder("C:\test")
        HandleFolder fldr
    End Sub
    
    
    Sub HandleFolder(fldr As Folder)
        Dim f As File
        Dim subFldr As Folder
    
        ' loop thru files in this folder
        For Each f In fldr.Files
            Debug.Print f.Path
        Next
    
        ' loop thru subfolders
        For Each subFldr In fldr.SubFolders
            HandleFolder subFldr
        Next
    End Sub
    
    0 讨论(0)
  • 2020-12-12 07:07

    IDK it it helps but this is a pretty solid frame

     path = "yourpath" & "\"
     Filename = Dir(path & "*.fileextension")
    
     Do While Len(Filename) > 0
         'some code
         Filename = Dir
     Loop
    
    0 讨论(0)
提交回复
热议问题