Loop through workbooks

K

Kirk P.

This code is producing a run time 1004 "file not found" error, however it is
actually naming the file it can't find in the error message. It seems odd it
displays the name of the file if it can't find it. Here's the code - can
anyone spot the problem?

Sub RunLoop()

Dim Folder As String
Dim FName As String
Dim bk As Workbook

Folder = "C:\Databases\Paypal\Bank Files\Sales\"
FName = Dir(Folder & "*.CSV")
Do While FName <> ""
Set bk = Workbooks.Open(Filename:=FName)
'run my macro here

bk.Close savechanges:=True
FName = Dir()
Loop

End Sub
 
J

Joel

from:
Set bk = Workbooks.Open(Filename:=FName)


to:
Set bk = Workbooks.Open(Filename:=Folder & FName)
 

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