Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default DIR not working after first workbook opened.

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default DIR not working after first workbook opened.

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


"Barb Reinhardt" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default DIR not working after first workbook opened.

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

Barb Reinhardt wrote:

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

"Barb Reinhardt" wrote:

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula not working when opened by another user K Excel Discussion (Misc queries) 0 October 27th 08 03:18 PM
Opening a workbook if not opened, going to it if already opened neotokyo[_3_] Excel Programming 0 September 24th 04 08:56 PM
Opening a workbook if not opened, going to it if already opened neotokyo[_2_] Excel Programming 1 September 24th 04 07:17 PM
Opening a workbook if not opened, going to it if already opened neotokyo Excel Programming 1 September 24th 04 06:33 PM
How to see if the opened workbook is opened by another user ? balexis Excel Programming 1 August 18th 04 04:11 PM


All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"