macro - open all files in a folder

前端 未结 3 1373
小鲜肉
小鲜肉 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:38

    Try the below code:

    Sub opendfiles()
    
    Dim myfile As Variant
    Dim counter As Integer
    Dim path As String
    
    myfolder = "D:\temp\"
    ChDir myfolder
    myfile = Application.GetOpenFilename(, , , , True)
    counter = 1
    If IsNumeric(myfile) = True Then
        MsgBox "No files selected"
    End If
    While counter <= UBound(myfile)
        path = myfile(counter)
        Workbooks.Open path
        counter = counter + 1
    Wend
    
    End Sub
    

提交回复
热议问题