Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetOpenFileName - using network folder

Posted on 2008-06-16
4
Medium Priority
?
2,224 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

715 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