Solved

GetOpenFileName - using network folder

Posted on 2008-06-16
4
1,875 Views
Last Modified: 2013-12-26
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
Comment
Question by:gbergsma
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Jaffa0
ID: 21800802
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
 

Author Comment

by:gbergsma
ID: 21801094
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
 
LVL 6

Accepted Solution

by:
Jaffa0 earned 50 total points
ID: 21801195
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
 

Author Closing Comment

by:gbergsma
ID: 31467807
Fantastic - thanks Jaffa0. Seems like Microsoft finally fixed this stupid problem with Vista. Cheers  Greg
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now