Help with - Get File dialoge code

T

Tempy

Hello all, i am using the code below to open a dialog to retrieve a file
and it works great if i name the drive letter, howver i need to put in
the server IP, as not all users log the drive on the same letter. The
path enclosed in brackets is the path i need to point to. Could somebody
please help with this code.

Sub TestGet()
ChDrive "c" > (" \\zapad01\sapinter ")
ChDir "C:\Documents and Settings\Stoutle\SapWorkDir"
("\\zapad01\sapinter\ZA-TM-RECON\UPLOAD")
fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If
End Sub

Thanks in advance

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
 
D

Dave Peterson

The chdrive won't work on network drives.

But you can use an API call:

Option Explicit
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub
Sub testme02()

Dim mySavedPath As String

mySavedPath = CurDir

ChDirNet "\\zapad01\sapinter\ZA-TM-RECON\UPLOAD"

'do your stuff

ChDirNet mySavedPath

End Sub

This actually works with mapped drives, too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top