Need to be able to control initial directory on folder dialog

debsmith

New Member
Joined
Apr 20, 2011
Messages
2
Hello,
Can some one help me please...I need the folder dialog to always start at the C: directory but it seems to go wherever I was last working. Here is the code:
Code:
Public Sub Get_Folder()
On Error GoTo ErrorHandler
Dim fldr As FileDialog
Dim sItem As String
Dim sInitDir As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
sInitDir = CurDir
With fldr
    .Title = "  Please select a folder where program files can be placed.   Clicking OK selects the C Drive."
    .AllowMultiSelect = False
    .InitialFileName = "C:"
    If .Show <> -1 Then GoTo NextCode
    sItem = .SelectedItems(1)
End With
ChDir sInitDir
NextCode:
Range("B2").Value = sItem
Set fldr = Nothing
ChDir sInitDir
Exit Sub
ErrorHandler:
ChDir sInitDir
Exit Sub
End Sub
I tried putting this line in at the beginning
Code:
ChDir "C:"
but it had no effect.
Thank you.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Perhaps it should be

Rich (BB code):
With fldr
    .Title = "  Please select a folder where program files can be placed.   Clicking OK selects the C Drive."
    .AllowMultiSelect = False
    .InitialFileName = "C:"
    If .Show = False Then GoTo NextCode
    sItem = .SelectedItems(1)
End With
ChDir sInitDir
NextCode:
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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