Get all file names and list in a worksheet with VBA

babshire

Board Regular
Joined
Dec 10, 2014
Messages
64
Hey All,

I'm using Office 365 and trying to write a macro that lists all of the excel file name in the directory "C:\Users\[username]\Desktop\49" into a worksheet

I used to have a macro that did this but can't find it now and I've searched online and found a few that use filesystemobject but can't get those to work and have no idea why (did Microsoft remove this?)

If anyone has one stuffed in an archive somewhere I'd be appreciative. Apologies if this gets frequently asked, I didn't have any luck when I searched for it.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You could try this, you'll need to define the path in sPath


Code:
sFileFound = Dir(sPath)

While sFileFound <> ""
       sFileFound = Dir()
Wend
 
Upvote 0
Thank you! that worked perfectly.

Everything I found on Google was magnitudes more difficult and cumbersome than this. Appreciate it. It's been a while since I've used VBA so I'm a bit rusty.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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