macro - open all files in a folder

前端 未结 3 1374
小鲜肉
小鲜肉 2020-12-08 11:24

I want to open all files in a specified folder and have the following code

Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = \"\\\\ILAFI         


        
3条回答
  •  伪装坚强ぢ
    2020-12-08 11:46

    You can use Len(StrFile) > 0 in loop check statement !

    Sub openMyfile()
    
        Dim Source As String
        Dim StrFile As String
    
        'do not forget last backslash in source directory.
        Source = "E:\Planning\03\"
        StrFile = Dir(Source)
    
        Do While Len(StrFile) > 0                        
            Workbooks.Open Filename:=Source & StrFile
            StrFile = Dir()
        Loop
    End Sub
    

提交回复
热议问题