Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Opening Excel-files in several directories

Bob Philips gave me the solution (see hereunder) to open Excel-files in a
certain directory. Is it also possible to change the directory after
finishing this and restart the job from the beginning? In other words: is it
possible to change the line
"sFile = Dir("C:\TestFolders\*.xls", vbNormal)" into
"sFile = Dir("C:\TestFolders2\*.xls", vbNormal)" by a For..Next loop?

Dim sFile As String
sFile = Dir("C:\TestFolders\*.xls", vbNormal)
If sFile < "" Then
Do
'Do your stuff
Debug.Print sFile
sFile = Dir


Loop Until sFile = ""
End If



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Opening Excel-files in several directories

Sub OpenFiles()
Dim v as Variant, sFile as String, i as Long
v = Array("C:\TestFolders\*.xls", _
"C:\TestFolders2\*.xls", _
"C:\TestFolders3\*.xls")
Dim sFile As String
for i = lbound(v) to ubound(v)
sFile = Dir(v(i), vbNormal)
Do while sFile < ""
'Do your stuff
Debug.Print Left(v(i),len(v(i))-5) & sFile
sFile = Dir
Loop Until sFile = ""
Next i
End sub

--
Regards,
Tom Ogilvy


"Dutch76" wrote:

Bob Philips gave me the solution (see hereunder) to open Excel-files in a
certain directory. Is it also possible to change the directory after
finishing this and restart the job from the beginning? In other words: is it
possible to change the line
"sFile = Dir("C:\TestFolders\*.xls", vbNormal)" into
"sFile = Dir("C:\TestFolders2\*.xls", vbNormal)" by a For..Next loop?

Dim sFile As String
sFile = Dir("C:\TestFolders\*.xls", vbNormal)
If sFile < "" Then
Do
'Do your stuff
Debug.Print sFile
sFile = Dir


Loop Until sFile = ""
End If



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Opening Excel-files in several directories

Thanks Tom!

"Tom Ogilvy" wrote:

Sub OpenFiles()
Dim v as Variant, sFile as String, i as Long
v = Array("C:\TestFolders\*.xls", _
"C:\TestFolders2\*.xls", _
"C:\TestFolders3\*.xls")
Dim sFile As String
for i = lbound(v) to ubound(v)
sFile = Dir(v(i), vbNormal)
Do while sFile < ""
'Do your stuff
Debug.Print Left(v(i),len(v(i))-5) & sFile
sFile = Dir
Loop Until sFile = ""
Next i
End sub

--
Regards,
Tom Ogilvy


"Dutch76" wrote:

Bob Philips gave me the solution (see hereunder) to open Excel-files in a
certain directory. Is it also possible to change the directory after
finishing this and restart the job from the beginning? In other words: is it
possible to change the line
"sFile = Dir("C:\TestFolders\*.xls", vbNormal)" into
"sFile = Dir("C:\TestFolders2\*.xls", vbNormal)" by a For..Next loop?

Dim sFile As String
sFile = Dir("C:\TestFolders\*.xls", vbNormal)
If sFile < "" Then
Do
'Do your stuff
Debug.Print sFile
sFile = Dir


Loop Until sFile = ""
End If



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
Stop Excel from locking files/directories you AREN'T working on? Your Display Name here... Excel Discussion (Misc queries) 1 November 20th 09 01:14 AM
VBA - Looping thro same naming files in 2 directories........PLEASE HELP Manju[_3_] Excel Programming 0 March 10th 06 03:26 PM
How do I get excel files to open automatically from directories? Damian Excel Discussion (Misc queries) 2 January 3rd 06 02:51 PM
hyperlinks to files in all sub-directories Steve Mackay Excel Programming 2 February 23rd 05 08:58 PM
Listing files in directories. skmr3 Excel Programming 0 July 11th 03 12:50 AM


All times are GMT +1. The time now is 12:10 AM.

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"