macro - open all files in a folder macro - open all files in a folder vba vba

macro - open all files in a folder

You have to add this line just before loop

    MyFile = DirLoop

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()    LoopEnd Sub

Try the below code:

Sub opendfiles()Dim myfile As VariantDim counter As IntegerDim path As Stringmyfolder = "D:\temp\"ChDir myfoldermyfile = Application.GetOpenFilename(, , , , True)counter = 1If IsNumeric(myfile) = True Then    MsgBox "No files selected"End IfWhile counter <= UBound(myfile)    path = myfile(counter)    Workbooks.Open path    counter = counter + 1WendEnd Sub