Code in VBScript to return an Object/array of files in a directory?

srj19

Board Regular
Joined
Aug 23, 2006
Messages
152
I've done this in VBA using Application.Filesearch and then a new method when 2007 eliminated that option.

I've yet to figure out how, or even if I can select a directory, and then work with every file in that directory.

Or even if it's possile to get a file/directory dialog that allows me to click and select a specific file.

Thanks for help,

Scott
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I did manage to do it with some similar code to what I used before however it's only allowing the selection of a single file and not the file/folder.

I don't see any options for special code pastes so here is what I'm using that "works" to yeild the entire path to the selected file but I'm wondering if I'm missing a small tweak that would make this return the path to the file/folder itself sans the file.

Dim xlApp
Dim fd
Dim owbk
Dim dirr
Dim msoFileDialogFolderPicker
msoFileDialogFolderPicker = 1

Set xlApp = CreateObject("Excel.Application")

Set fd = xlApp.FileDialog(msoFileDialogFolderPicker)

With fd
.Title = "Please navigate to the folder to be processed"
.InitialFileName = "C:\Documents and Settings\user\Desktop\"
.Filters.Add "Excel Files", "*.xls*", 1
.AllowMultiSelect = True
If .Show = -1 Then
dirr = .SelectedItems(1)
end if
End With


msgbox(dirr)
 
Upvote 0
I've done this in VBA using Application.Filesearch and then a new method when 2007 eliminated that option.

I've yet to figure out how, or even if I can select a directory, and then work with every file in that directory.
Scott

I normally use Shell to pick a directory (it can also take a default suggestion), and the Dir to process each file in that given directory (recursion can be used to process sub-folders)

I have a sample here that uses this approach to consolidate all the Excel files in a folder to a single summary workbook

Cheers

Dave
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,877
Members
452,949
Latest member
Dupuhini

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