Asking user to specify a directory

GeneralShamu

Board Regular
Joined
Jul 6, 2007
Messages
127
I am trying to run code on all the XLS files in a directory. I want the user to specify what directory they want to execute the code on though.

I don't want this to be done by the user typing out the directory but selecting it as they would a file.

Does anyone know how to do this?

Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")
is what is used for the user selecting a single file/workbook.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try something like this...
<font face=Courier New>    <SPAN style="color:#007F00">' Prompt user to select a folder</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Application.FileDialog(msoFileDialogFolderPicker)<br>        .InitialFileName = "C:\Temp\"               <SPAN style="color:#007F00">' Default path</SPAN><br>        .Title = "Please Select a Folder"<br>        .ButtonName = "Select Folder"<br>        .AllowMultiSelect = <SPAN style="color:#00007F">False</SPAN><br>        .Show<br>        <SPAN style="color:#00007F">If</SPAN> .SelectedItems.Count = 0 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>   <SPAN style="color:#007F00">' User clicked cancel</SPAN><br>        MyPath = .SelectedItems.Item(1)<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

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