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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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