Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Open Files in Folder

Hi

I have been using this code to open all XL files in a certain
directory. Works well sometimes but if I am in Excel and go to File -
Open and change the directory to a completly different drive the Dir
function remembers this drive rather than the one I am telling it.
What can I do to force the Dir to always look at my specific
directory?

Thanks


Sub aaa()
Dim sPath As String
Dim sfil As String
Dim strName As String

sPath = "C:\Users\Test\Excel\"
sfil = Dir("*.xls")
ChDir sPath

Do While sfil < ""
strName = sPath & sfil
Workbooks.Open (strName)
sfil = Dir
Loop

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 320
Default Open Files in Folder

For ChDir to work, you may need to use ChDrive:
ChDrive "C"
ChDir sPath

"Chad" wrote in message
...
Hi

I have been using this code to open all XL files in a certain
directory. Works well sometimes but if I am in Excel and go to File -
Open and change the directory to a completly different drive the Dir
function remembers this drive rather than the one I am telling it.
What can I do to force the Dir to always look at my specific
directory?

Thanks


Sub aaa()
Dim sPath As String
Dim sfil As String
Dim strName As String

sPath = "C:\Users\Test\Excel\"
sfil = Dir("*.xls")
ChDir sPath

Do While sfil < ""
strName = sPath & sfil
Workbooks.Open (strName)
sfil = Dir
Loop

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Open Files in Folder

Thanks for the reply Bob appreciate your help.

sFil = Dir(sPath & "*.xls")

Your assistance and the above line helped solve the problem. Thanks
again.
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
User selection of folder and open all .xls files within folder Barb Reinhardt Excel Programming 4 April 14th 07 01:41 PM
Open files in folder - skip if already open Steph[_3_] Excel Programming 6 March 25th 05 06:49 PM
Open all files in a folder Daniel Van Eygen Excel Programming 5 August 24th 04 04:48 PM
Open Excel files in a folder Tom Ogilvy Excel Programming 0 August 20th 03 04:59 PM
open all files in a folder and ... walt Excel Programming 5 August 7th 03 02:23 AM


All times are GMT +1. The time now is 01:00 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"