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
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,389
Messages
5,571,850
Members
412,421
Latest member
Rimo86
Top