Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

macro - open all files in a folder

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 = "\\ILAFILESERVER\Public\Documents\Renewable Energy\FiTs\1 Planning
           Department\Marks Tracker\Quality 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.

like image 325
Ross McLaughlin Avatar asked Jun 22 '12 08:06

Ross McLaughlin


1 Answers

You have to add this line just before loop

    MyFile = Dir
Loop
like image 155
Siddharth Rout Avatar answered Sep 28 '22 19:09

Siddharth Rout