On 2002-04-04 18:32, turbotoan wrote:
Hi,
I need to open a file using the network UNC name instead of the drive letter. What might be drive "P" to one user, may be drive "Q" for another. But both point to "server1".
Can this be done?
I tried using the Chdrive method in the past & it didn't work. What do you think?
Thanks a bunch.
This message was edited by turbotoan on 2002-04-04 18:32
As you have found out, neither ChDrive or CHDir recognize UNC paths. You will need to use an API function.
Try something like this.<pre/>
Option Explicit
Private Declare Function SetCurrentDirectoryA Lib "kernel32" _
(ByVal lpPathName As String) As Long
'// Function Discription:
'// :The SetCurrentDirectory function changes the current
'//
irectory for the current process.
'//
'// Parameter Discription:
'// :lpPathName
'// : Points to a null-terminated string that specifies the path
'// : to the new current directory.
'// : This parameter may be a relative path or a fully qualified path.
'// : In either case, the fully qualified path of the specified directory
'// : is calculated and stored as the current directory.
'// :
'// : Succeed Value = NonZero
'// : Fail Value = Zero
'// :
Sub SetDir_UNC()
Dim sServer As String
Dim sIniPath As String
Dim sFullPathFileName As String
Dim oSuccess
'// Set the server variable here
sServer = "\ServerShare"
'// Store the current directory for later restoration.
sIniPath = CurDir
'// Set the new current directory to your UNC path.
oSuccess = SetCurrentDirectoryA(sServer)
'// Check if successfully connected
If oSuccess = 0 Then MsgBox "Unable to connect to " & sServer: Exit Sub
'// Show the GetOpenFilename dialog.
sFullPathFileName = Application.GetOpenFilename
'// Exit if the user cancells the dialog.
If sFullPathFileName = "False" Then Exit Sub
'// Otherwise continue.....
'// Lastly.... restore to the users initial directory.
SetCurrentDirectoryA sIniPath
End Sub</pre>