Open file from a designated path

u742884

Board Regular
Joined
Jun 23, 2002
Messages
126
I am trying to write code that prompts users to open files from a specific path. I am using GetOpenFilename, which works great except that the File-Open dialog box starts with your default path (or the last one you opened something from). I want it start in a designated path.

Thanks in advance for your help!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
At the moment I can't remember if it actually works, but it's worth a shot: you can try changing the directory to what you want before you call the GetOpenFileName:

Code:
ChDir "C:\This Folder\"

You may also need to change the drive if you're looking elsewhere. You can use the ChDrive statement for that. For example: ChDrive "H:"
 
Upvote 0
I have tested this and works for me.

ChDrive "c:\" " I.E any network or local drive first
ChDir "C:\folder path" ' Then the path seems to work for me.

Then I use

Code:
Application.GetOpenFilename(sFilter, , sTitle, , False)
 
Upvote 0
That worked afterall. I think in my prior attempts, I left off the "\" in the ChDrive statement and that statement would error out. Since I wasn't sure if it was a real command since I had guessed on based on the ChDir command, I took it out and just tried with ChDir MyPath.

Together it worked.
ChDrive "Q:\"
ChDir MyPath

Thank you! That was driving me crazy.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

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
Back
Top