Question posted 2012 · +7 upvotes
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 = "\ILAFILESERVERPublicDocumentsRenewable EnergyFiTs1 Planning
DepartmentMarks TrackerQuality Control Reports"
MyFile = Dir(MyFolder & "*.xlsx")
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "" & MyFile
Loop
End Sub
The problem I have is that it just keeps trying to open the first file in the folder repeatedly and won’t move on. Can anybody help, I’m a bit of a novice at VBA and could really do with some assistance. I’m trying to open around 30 reports that are all in .xlsx format. Many thanks in advance.
Accepted answer +14 upvotes
You have to add this line just before loop
MyFile = Dir
Loop
Top excel-vba Q&A (6)
- How to clear the entire array? +58 (2010)
- How to change Format of a Cell to Text using VBA +55 (2011)
- Download attachment from Outlook and Open in Excel +43 (2012)
- Can a VBA function in Excel return a range? +36 (2009)
- 2 Dimensional array from range +34 (2013)
- Hiding an Excel worksheet with VBA +33 (2009)
excel-vba solutions on this site
.