Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing current drive

Status
Not open for further replies.

hughesai

Technical User
Joined
Aug 1, 2002
Messages
101
Location
GB
Hi,

I have a file I want to open through VBA.
It is always on a network area e.g. \\server\sharename$.
I am using the code below to pick the filename
stFileName = Application.GetOpenFilename("Text Files (*.txt),*.txt")
(GetOpenFilename is an Excel function - I have imported the Excel library into my project)
This always points to C:\My Documents.
I have tried uing ChDir ("\\server\sharename$") to change the current directory.
However, this does not change the current drive, and the GetOpenFilename method is still pointing to My Documents on C:

Can anyone tell me how to point to my network area?

Thanks,

Aidan Hughes



 
Thanks mp9.

Unfortunately this doesn't seem to work.

ChDrive expects a drive letter and, to quote the help file, "If the drive argument is a multiple-character string, ChDrive uses only the first letter."

This surprises me as I thought M$ would have included the facility to use full path names.

I can not be sure that all my users will have this area mapped to the same drive letter, and in fact I prefer them not to have it mapped at all - it keeps them out of areas they should not be in other than to pick up this file ! ! !

Any further thouhgts?

Aidan
 
Good point. You might try the article at which explains how to return a UNC filepath from a drive letter - you could use this to work out which drive letter the user has the specified server\share mapped to, and then use ChDrive() to switch to it. [pc2]
 
Why don't you ditch the excel dialog and use the api version.
has the standard code, you don't need to set references to anything, you don't need any special ocx's installed, it's all done through code.
There are plenty of examples to look at & the argument you need to pay closer attention to is the InitialDir argument.

hth


Ben ----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top