Directory/File Open Dialog

jonesy241

Board Regular
Joined
Dec 16, 2004
Messages
174
I use a bunch of folders that are all over the place on my network. I would like to type in a code and change the directory and then open the file open dialog box to allow me to 'jump' right to the folder I need.

I understand there are "favorites" on the left panel of the open file dialog box but thats not the way I want to do this. Obviously the path names are not all so simple or even on my C drive.

Basically if i remove the file dialog part at the bottom I can change the directory to the proper folder no problem. But when I use the file dialog part next it opens it up to the same directory each time.

Let me know if I am using the wrong file open dialog thing.


Code:
Sub my_districts()

dist = InputBox("Enter the district.")

Select Case dist
Case Is = "can"
fldr = "C:\canton"
Case Is = "ec"
fldr = "C:\east central"
Case Is = "mid"
fldr = "C:\midland"
Case Is = "man"
fldr = "C:\manor"
Case Is = "geo"
fldr = "C:\george"
Case Else
MsgBox ("Bad District")
Exit Sub
End Select

ChDrive (fldr)
ChDir (fldr)

Application.FileDialog(msoFileDialogOpen).Show

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi

Take a look at the "InitialFileName" Property - if you set this to a path as opposed to a path\filename combo it will use that path as it's initial directory.

From the helpfile:

Set or returns a String representing the path and/or file name that is initially displayed in a file dialog box. Read/write.

expression.InitialFileName
expression Required. An expression that returns one of the objects in the Applies To list.

Remarks
You can use the '*' and '?' wildcard characters when specifying the file name but not when specifying the path. The '*' represents any number of consecutive characters and the '?' represents a single character. For example, .InitialFileName = "c:\c*s.txt" will return both "charts.txt" and "checkregister.txt."

If you specify a path and no file name, then all files that are allowed by the file filter will appear in the dialog box.

Cheers
Martin
 
Upvote 0
Thanks for the help Martin. I actually started looking around a little more and I found what I was looking for originally.


Code:
Application.Dialogs(xlDialogOpen).Show

I should have probably found it before I posted but in case anyone is wondering there it is.

Paul
 
Upvote 0

Forum statistics

Threads
1,222,900
Messages
6,168,926
Members
452,227
Latest member
sam1121

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