Fro Each Next Loop Troubles

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
 
C

Chip Pearson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top