GetOpenFileName Default Directory?

FilipT

New Member
Joined
Jul 25, 2011
Messages
16
How can I set a default directory to be shown once i run the getopenfilename method so i dont have to browse through folders to get to the desired one? All help appreciated
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
this has been ripped out of one of my macros:

Code:
ChDrive "G:\"
    ChDir "g:\Underground\Operations\Job Allocation Sheets\Daily Job Status sheet A4\"
    strFile = Application.GetOpenFilename

the file the user selects will be in strFile
 
Upvote 0
Here is another method.
Code:
Sub Test()
  MsgBox FileOpen("x:\", "Kens Files", "*.xls; *.xlsx; *.xlsm")
End Sub


Function FileOpen(initialFilename As String, _
  Optional sDesc As String = "Excel (*.xls)", _
  Optional sFilter As String = "*.xls") As String
  With Application.FileDialog(msoFileDialogOpen)
    .ButtonName = "&Open"
    .initialFilename = initialFilename
    .Filters.Clear
    .Filters.Add sDesc, sFilter, 1
    .Title = "File Open"
    .AllowMultiSelect = False
    If .Show = -1 Then FileOpen = .SelectedItems(1)
  End With
End Function
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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