Fro Each Next Loop Troubles

  • Thread starter Thread starter Murphy
  • Start date Start date
M

Murphy

I want to open each file in a folder and edit it, close it and go to
the next file. My folder will not have a constant number of files. I
have the code for the editing but am having trouble with the looping.
Could someone please help me?

Thanks,
Murphy
 
Murphy,

Use the Dir command with a Do Loop. E.g.,

Dim FName As String
Dim WB As Workbook
ChDrive "C:"
ChDir "C:\FolderName"
FName = Dir ("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(FName)
' do something with WB
WB.Close SaveChanges:=True
FName = Dir()
Loop
 
Back
Top