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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

pritcham

Board Regular
Joined
Oct 26, 2005
Messages
128
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
 

jonesy241

Board Regular
Joined
Dec 16, 2004
Messages
174
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,006
Messages
5,834,835
Members
430,324
Latest member
bosphoruskid

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