PDA

View Full Version : Need macro to list folder with name and size in excel. Thanks



pedie
07-24-2010, 07:51 PM
Hi,

I'm wanting excel to find list of folders, name and size...
it does work, i dont know..it is giving error message.
code source
vbaexpress kb/getarticle.php?kb id=1042

also please check this link
LINK REMOVED (No permission)


Option Explicit


Sub GetFileNames()

Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$

InitialFoldr$ = "G:\" '<<< Startup folder to begin searching from

With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub

Thanks everyone for helping.

Pedie.

Simon Lloyd
07-24-2010, 11:03 PM
Firstly i have deleted all your other messages in other threads which were simply asking how do i post.

Secondly why is it not working? what is the error it gives? which version of excel are you using?

GTO
07-25-2010, 04:21 AM
Cross-Posted:

http://www.mrexcel.com/forum/showthread.php?p=2387212

Duplicate:
http://www.mrexcel.com/forum/showthread.php?t=483566

Reference to VBAX KB Article:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=1042

Reference to Application.FileSearch method:
http://www.automateexcel.com/2008/09/13/vba-list-of-all-files-contained-within-a-directory/


@Pedie:

Please see Here (http://www.excelguru.ca/node/7)

Please read Mr. Puls' article in the above link. I cannot imagine a kindlier way of advising reference cross-posting; kudos to Ken.

I believe you mention working in 2007. .FileSearch was ditched in 2007. I would suggest you keep after xenou's suggestion, albeit, I would most likely go late-bound.

Mark

Simon Lloyd
07-25-2010, 06:14 AM
Mark thanks for that and the advice to Pedie :)

anasttin
07-26-2010, 06:22 AM
Hi,

You can get a free Excel file that lists files in any selected folder automatically at the website below.

excelwell-excel-templates.110mb.com

Hope that helps.

:o)

nandakumar
08-03-2010, 09:45 AM
look at this link

http://www.vbaexpress.com/kb/getarticle.php?kb_id=232


http://www.vbaexpress.com/kb/default.php?action=13&kb_id=232

anasttin
08-03-2010, 12:55 PM
I really like that file Nandakumar, but does anyone know how to alter the macro code so it lists the contents of the specified folder AS WELL AS the contents of all its sub folders in the same way? You'd obviously need another column showing the folder name each file is in.

That would be fantastic.

Thanks