OS question

khushbu.bhandari

New Member
Joined
Mar 16, 2011
Messages
12
Is there a possibility to get details of folder contents/no.of files in a particular folder on the Operating System.

Can this information be captured on Excel or DOS Command Prompt?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This will list the Excel files in a folder

Code:
Sub ListFiles()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "C:\example"
MyFile = Dir(MyFolder & "\*.xls")
Do While MyFile <> ""
    j = j + 1
    Cells(j, 1).Value = MyFile
    MyFile = Dir
Loop
End Sub
 
Upvote 0
After writing this Macros, Where does the information captured.

I copied this macro and added the drive MyFolder = "C:\example"

Another thing i keep getting an error message stating that the Run Time error '5'- Invalid Procedure or call argument
 
Upvote 0
You must have a folder called example on your C: drive. The output is to the cells in a worksheet (VoG's code, by the way, looks for excel files with xls extensions, not all files).
Macro basics here (among other tutorials to be found on the internet):
http://www.anthony-vba.kefra.com/vba/vbabasic1.htm

Can this information be captured on Excel or DOS Command Prompt?
Output to a command prompt requires no vba. Just type dir at the command prompt.

Listing files in a folder is a common request and you'll finding many examples with a little searching on google.
This one seems good and has a training video and detailed instructions:
http://excelexperts.com/VBA-Tips-List-Files-In-A-Folder

ξ
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,707
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