Hi:
I want to open all Excel files in a specified folder and have the following code, but it didn't work:
Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = "\\G:\Functional Teams\Finance\2013\Consolidation & Reporting\1013\Financial Package"
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
MyFile = Dir
Loop
End Sub
It gave me a message Run-time error'52' "Bad file name or number", and the error was highlighted in the line MyFile = Dir(MyFolder & "\*.xls")
Why was it? How should I correct it?
Any help is very appreciated. Or please advise me other codes that work.
I'm using Excel 2010.
Thanks
Henry
I want to open all Excel files in a specified folder and have the following code, but it didn't work:
Sub OpenFiles()
Dim MyFolder As String
Dim MyFile As String
MyFolder = "\\G:\Functional Teams\Finance\2013\Consolidation & Reporting\1013\Financial Package"
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
MyFile = Dir
Loop
End Sub
It gave me a message Run-time error'52' "Bad file name or number", and the error was highlighted in the line MyFile = Dir(MyFolder & "\*.xls")
Why was it? How should I correct it?
Any help is very appreciated. Or please advise me other codes that work.
I'm using Excel 2010.
Thanks
Henry