Solved

GetOpenFileName - using network folder

Posted on 2008-06-16
4
2,035 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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