ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using Application.FileDialog(msoFileDialogFolderPicker) (https://www.excelbanter.com/excel-discussion-misc-queries/179729-using-application-filedialog-msofiledialogfolderpicker.html)

Ayo

Using Application.FileDialog(msoFileDialogFolderPicker)
 
I am trying to use Application.FileDialog(msoFileDialogFolderPicker)
to get a folder and run a macro on each file in that folder. I was using
this approach befo
folderspec = Application.InputBox(prompt:="Input Folder Path", Title:="Get
Folder", Type:=2)
but it requires someone to copy and paste the folder path. But I want to
use a different approach where the filedialog opens and you can pick the
folder directly. I know Application.FileDialog(msoFileDialogFolderPicker) is
what is needed but I can figure out what next. This is what I have, and it's
giving me an error

folderspec = Application.FileDialog(msoFileDialogFolderPicker)
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
s = f1.Path
Workbooks.Open Filename:=s, UpdateLinks:=0
Thanks for the help.


Kevin B

Using Application.FileDialog(msoFileDialogFolderPicker)
 
This site will provide you with a the Browse Folder dialog box, which will
return the name of the selected folder:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=246
--
Kevin Backmann


"Ayo" wrote:

I am trying to use Application.FileDialog(msoFileDialogFolderPicker)
to get a folder and run a macro on each file in that folder. I was using
this approach befo
folderspec = Application.InputBox(prompt:="Input Folder Path", Title:="Get
Folder", Type:=2)
but it requires someone to copy and paste the folder path. But I want to
use a different approach where the filedialog opens and you can pick the
folder directly. I know Application.FileDialog(msoFileDialogFolderPicker) is
what is needed but I can figure out what next. This is what I have, and it's
giving me an error

folderspec = Application.FileDialog(msoFileDialogFolderPicker)
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
s = f1.Path
Workbooks.Open Filename:=s, UpdateLinks:=0
Thanks for the help.



All times are GMT +1. The time now is 02:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com