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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
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,351
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
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,351
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,170,931
Messages
5,872,769
Members
432,944
Latest member
mj02

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