0

very new to VBA. I'm trying to write a program that opens files in one folder, updates them and saves them in a new folder. I have that part done, the issue is that the below Do While Loop that cycles the code through the files in the given folder but doesn't end the loop when each file has been opened, edited and saved as in a the next period's folder. It just keeps repeating the loop. Any ideas? Thanks, Charlie

Do While (WLFile) > 0
    Set WB = Workbooks.Open(WLPath & WLFile, UpdateLinks:=3)
    ActiveWorkbook.SaveAs Filename:=MyFolder & "\" & _
                                    "20" & WLYear & "\" & _
                                    QTR & "Q" & "\" & _
                                    WLFile
    ActiveWorkbook.Close
John Coleman
  • 51,337
  • 7
  • 54
  • 119
cmcgrath
  • 77
  • 1
  • 5
  • How is the variable `WLFile` updated? Nothing in your code describes how that variable is initialized and how it is supposed to change from one pass through the loop to the next. – John Coleman Dec 19 '15 at 20:22

1 Answers1

0

You could count the number of files in your directory and then use that for your loop counter. I found the following answer on this site to reference that counts all files of a specific extension in a directory and displays the result.

https://stackoverflow.com/a/16756658/5692872

Community
  • 1
  • 1
NinjaLlama
  • 167
  • 3
  • 14
  • Yes instead the macro mentioned in the link can be changed as a function and can be called every time to get number of files and later part is already on ur code – Kanike Vamshi Krishna Dec 20 '15 at 05:11