![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Wisconsin - USA
Posts: 62
|
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 ] |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Try something like this. Option Explicit Private Declare Function SetCurrentDirectoryA Lib "kernel32" _ (ByVal lpPathName As String) As Long '// Function Discription: '// :The SetCurrentDirectory function changes the current '// '// '// 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 |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|