DIR not working after first workbook opened.

B

Barb Reinhardt

I have this snippet of code

myFile = Dir(myFolder & "*.xls")
Debug.Print myFile

Do While myFile <> ""
On Error Resume Next
Application.AutomationSecurity = msoAutomationSecurityLow
Set oWB = Workbooks.Open(myFolder & myFile)
Application.AutomationSecurity = msoAutomationSecurityByUI

On Error GoTo 0
If Not oWB Is Nothing Then
'Do stuff
application.displayalerts = false
oWB.SaveAs myNewFolder & oWB.Name
Application.DisplayAlerts = True
oWB.Close

End If
myFile = Dir() '<~~~I get Run Time Error 5 here
Loop

I've done this before with no problem. What am I missing? FWIW, I've
declared all variables.

Thanks,
Barb Reinhardt
 
B

Barb Reinhardt

Never mind, I see the problem. I'm using DIR in another module. I'll have
to approach this another way.
Thanks,
Barb Reinhardt
 
D

Dave Peterson

I'd build an array of all the files first. Then process the files via that
array.
 

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