Full path name for the GetOpenFileName

HunterN

Active Member
Joined
Mar 19, 2002
Messages
479
Hi,

I know how to use the GetOpenFilename that displays a dialog box for
the user to choose a file to open. What I want to know is this: can you
specify the full path so that the dialog box opens only in a certain directory?

This is what I have, but it does not seem to work. It only opens the My Documents directory.


myPath = ThisWorkbook.Path
UF = Application.GetOpenFilename(FileFilter:=myPath & "\Old Supps\" & "Text Files(*.txt),*.txt", _
Title:="Text Files to Open")

Thanks,
Nancy
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Nancy

The FileFilter argument is for filtering files.

If you want to use a particular directory try using ChDir.
Code:
ChDir myPath & "\Old Supps\"
 

HunterN

Active Member
Joined
Mar 19, 2002
Messages
479
I sorry - but where do I put the change directory command?

ChDir myPath & "\Old Supps\"

Inside the GetOpenFilename or before I execute this Open Dialog box?

Nancy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Nancy

Put it before GetOpenFilename.
Code:
ChDir myPath & "\Old Supps\" 
 UF = Application.GetOpenFilename(FileFilter:="Text Files(*.txt),*.txt", _
Title:="Text Files to Open")
 

HunterN

Active Member
Joined
Mar 19, 2002
Messages
479

ADVERTISEMENT

I put in the code above the OpenFilename line, and it still doesn't change anything. It still opens up in My Documents area
:confused:

Nancy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Nancy

Did you also include the code for setting the value of mypath?

Are you on a network?
 

HunterN

Active Member
Joined
Mar 19, 2002
Messages
479
Yes to setting the code for myPath
It equals "H:\Public Test"


and Yes to am I on a network!

So does that matter?

Nancy
 

Forum statistics

Threads
1,137,193
Messages
5,680,082
Members
419,879
Latest member
jzl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top