Solved

GetOpenFileName - using network folder

Posted on 2008-06-16
4
1,918 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

816 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

11 Experts available now in Live!

Get 1:1 Help Now