Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Open Files in Folder

4 views
Skip to first unread message

Chad

unread,
Jan 7, 2010, 3:41:45 PM1/7/10
to
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

Bob Umlas

unread,
Jan 7, 2010, 4:27:54 PM1/7/10
to
For ChDir to work, you may need to use ChDrive:
ChDrive "C"
ChDir sPath

"Chad" <chadm...@yahoo.com> wrote in message
news:5455467a-e13e-40e4...@p8g2000yqb.googlegroups.com...

Chad

unread,
Jan 7, 2010, 7:05:59 PM1/7/10
to
Thanks for the reply Bob appreciate your help.

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

Your assistance and the above line helped solve the problem. Thanks
again.

0 new messages