Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2320
  • Last Modified:

GetOpenFileName - using network folder

Hi,

I am trying to use the GetOpenFileName function for a network folder location.

I understand that I need to use the ChDrive function in order to nominate a folder on a network drive. However I may not know the network drive as the pathname to search is entered by the user (using the SHBrowseForFolder function). They may traverse to the network folder from My Network Places and thus the first character of the path would not be the drive letter.

I have the code below, but it doesnt work in the above instance

Any suggestions on how to resolve this would be appreciated (besides forcing the user to enter a path from the network drive letter).

Cheers

Greg

    If Not ((UCase(Mid(DataWorkbook.path, 1, 1)) < "A") Or _
            (UCase(Mid(DataWorkbook.path, 1, 1)) > "Z")) Then
        ChDrive (Mid(DataWorkbook.path, 1, 1))
    End If
    ChDir (DataWorkbook.path)
    ImportFilename = Application.GetOpenFilename(FileFilter:="microsoft excel files (*.xls), *.xls", _
           Title:="Select File", MultiSelect:=False)
0
gbergsma
Asked:
gbergsma
  • 2
  • 2
1 Solution
 
Jaffa0Commented:
I don't think you need to use chdrive when you are using a network path. So if you wrap the ChDrive like this it should work (I think).
On Error Resume Next
ChDrive (Mid(DataWorkbook.Path, 1, 1))
ChDir (DataWorkbook.Path)
On Error GoTo 0

Open in new window

0
 
gbergsmaAuthor Commented:
Hi Jaffa0

Unfortunately the GetOpenFilename function expects the directory to exist on the current drive (which is C if you don't CHDrive the drive name).
The GetOpenFilename shows the My Documents folder if it doesnt find the nominated folder on the current drive.

The chdir is not the problem - its the GetOpenFilename
0
 
Jaffa0Commented:
Try this.
Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
...
 
SetCurrentDirectory DataWorkbook.Path
ImportFilename = Application.GetOpenFilename(FileFilter:="microsoft excel files (*.xls), *.xls", _
           Title:="Select File", MultiSelect:=False)

Open in new window

0
 
gbergsmaAuthor Commented:
Fantastic - thanks Jaffa0. Seems like Microsoft finally fixed this stupid problem with Vista. Cheers  Greg
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now