Excel - copy explorer folder list to excel
Asked By KK
27-Apr-07 08:16 AM
Hello
I want to develop a spreadsheet (Excel) which will have all the files in one
of my folders as on of its columns!
I have tried opening explorer , using copy & paste, but it doesn't seem to
work
Can anybody help please ?
Thanks
KK
INDEX
(1)
ROW
(1)
Application
(1)
Excel
(1)
Error
(1)
Worksheets
(1)
Name
(1)
Range
(1)
Mike replied...

Try this. Allows you to select file extension or serach on all files and then
select search folder. Puts the results in a new worksheet but that would be
easily changed:-
Option Explicit
Sub SrchForFiles()
Dim i As Long, z As Long, Rw As Long
Dim ws As Worksheet
Dim y As Variant
Dim fLdr As String, Fil As String, FPath As String
y = Application.InputBox("Please Enter File Extension - leave blank for
all files", "Info Request")
If y = False And Not TypeName(y) = "String" Then Exit Sub
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
fLdr = .SelectedItems(1)
End With
With Application.FileSearch
.NewSearch
.LookIn = fLdr
.SearchSubFolders = True
.Filename = y
Set ws = ThisWorkbook.Worksheets.Add(Sheets(1))
On Error GoTo 1
2: ws.Name = "FileSearch Results"
On Error GoTo 0
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Fil = .FoundFiles(i)
FPath = Left(Fil, Len(Fil) - Len(Split(Fil,
If Left$(Fil, 1) = Left$(fLdr, 1) Then
If CBool(Len(Dir(Fil))) Then
z = z + 1
ws.Cells(z + 1, 1).Resize(, 4) = _
Array(Dir(Fil), _
FileLen(Fil) / 1000, _
FileDateTime(Fil), _
FPath)
ws.Hyperlinks.Add Anchor:=Cells(z + 1, 1), _
Address:=.FoundFiles(i)
End If
End If
Next i
End If
End With
ActiveWindow.DisplayHeadings = False
With ws
Rw = .Cells.Rows.Count
With .[A1:D1]
.Value = [{"Full Name","Kilobytes","Last Modified", "Path"}]
.Font.Underline = xlUnderlineStyleSingle
.EntireColumn.AutoFit
.HorizontalAlignment = xlCenter
End With
.[E1:IV1 ].EntireColumn.Hidden = True
On Error Resume Next
Range(Cells(Rw, "A").End(3)(2), Cells(Rw, "A")).EntireRow.Hidden =
True
Range(.[A2 ], Cells(Rw, "C")).Sort [A2 ], xlAscending, Header:=xlNo
End With
Application.ScreenUpdating = True
Exit Sub
1: Application.DisplayAlerts = False
Worksheets("FileSearch Results").Delete
Application.DisplayAlerts = True
GoTo 2
End Sub
Mike
Jan Karel Pieterse replied...
Hi Kk,
In B1, enter your path and file wildcard, e.g.
c:\my documents\*.xls
Then select Insert, name, define.
Type FileList in the name box and
=FILES($B$1)
in the RefersTo box and hit enter.
Now in cell A1 type :
=INDEX(FILES,ROW())
copy down.
Note: Excel 2000 crashes if you copy a cell with this formula to another
worksheet.
Regards,
Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com
LukeMorag replied...
You might also want to take a look at the "List Files" program from
http://www.realezsites.com/bus/primitivesoftware/products.php
Its pretty easy to use, has a nice ReadMe file, and is adaptable to many uses.
--
Best Regards,
Luke Moraga
KK replied...
Jan
Thanks for the help, but I'm struggling to understand.
I cannot find the menu sequence Insert/name/define ! I suspect the problem
is that I have excel 2007 (sorry - I should have said so in my original
email)
Thanks again
KK
Roger Govier replied...
Hi
There was a small typo in Jan Karel's formula to be entered in A1
should have read
=INDEX(FILELIST,ROW())
In XL2007, to Insert the name Filelist, Formulas tab>Defined Names
section>Define Name
--
Regards
Roger Govier
Jan Karel Pieterse replied...
Hi Roger,
Thanks for jumping in and correcting my mistake.
Ron De bruin has a nice page which shows you what commands went where
in XL2007:
http://www.rondebruin.nl/0307commands.htm
Regards,
Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com
Roger Govier replied...
Hi Jan Karel
As the OP was from some time ago, I didn't know whether you were
In addition to the help that Ron has put on his site, I came across this
add-in from MS recently, which inserts a Get Started tab on the ribbon
with lots of useful help for new users when trying to get to grips with
the new Ribbon layout
http://snipurl.com/1jr7e
This includes an interactive guide where you can see a 2003 layout,
hover over the command and it will show you where that is now located.
Click on the command and the screen changes to XL2007 with the area of
the Ribbon highlighted.
There are direct links from the new ribbon tab to MS sites with demo
videos etc.
--
Regards
Roger Govier
KK replied...
Jan (and Roger )
Thanks again, this works nicely.
I can't seem to find help pages on the =FILES function, so is it a VBA
command or something ?
Are there other similar commands for getting file info, specifically can I
also read the file size ?
Thanks again
K
Jan Karel Pieterse replied...
Hi Kk,
It is an ancient xl4 macro function. Check out this page for more info:
http://www.jkp-ads.com/Articles/ExcelNames08.htm
Regards,
Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com

Changing a two-dimensional, one row array to one-dimensional Excel The typical way to accomplish the above diseminated in these newsgroups has been myArray2 = Application.Transpose(Application.Transpose(myArray1)) Less typical, but equally effective, is myArray2 = Application.Index(myArray1, 1, 0) Both of these methods have the following limitations: they don't work ChangeToOneD = arrOut End If Exit Function ErrMsg: Msg = "The function accepts only 2-dimensional, single row VBA arrays of a built-in type." MsgBox Msg, 16 End Function Function ArrayDimensions(InputArray If Not TypeName(InputArray) Like "*()" Then Msg = "#ERROR! The function accepts only arrays." If TypeOf Application.Caller Is Range Then ArrayDimensions = Msg Else MsgBox Msg, 16 End If Exit Function End dimensions ArrayDimensions = i - 2 End Function Alan Beban Excel Programming Discussions Error (1) VBA (1) Application.Transpose (1) Application.Caller (1) Application.Index (1) CCNumber (1) EnteredNumber (1) TypeName (1) It
JourProcheJour() Dim No_Ligne As Variant With Worksheets("Planning") 'nom feuille = E0 adapter .Activate No_Ligne = 3D Application.Match(CLng(Date), .Range("A2:A370"), 0) If Not IsError(No_Ligne) Then .Range("D" & No_Ligne).Select Else No_Ligne = 3D Application.Match(CLng(Date), .Range("A2:A370"), 1) If Date - Application Index([A2:A370], No_Ligne) < _ Application.Index([C2:C370], No_Ligne + 1) - Date Then Cells(No_Ligne, 3).Select Else Cells(No_Ligne + 2, 4 End If End If End With End Sub Excel - French Discussions Worksheets (1) Date (1) Application (1) IsNumeric (1) Activate (1) Range (1) Match (1) Sub JourProcheJour() Dim X As Variant As Range With Worksheets("Planning") .Activate Set Rg = .Range("A1:A" & .Range("A65536").End(xlUp).Row) X = Application.Match(CLng(DateSerial(Year(Now()), _ Month(Now()), Day(Now()))), Rg.Value2, 1
To delete specific color index row Excel Hi, I tried to run the macro code below, but it does not even ActiveSheet.Activate Range("A1").Select For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row If Rows(i).Interior.ColorIndex = 6 Then Rows(LastRow).Select Selection.Delete i = i + 1 MyRng As Range Dim LstCell As Integer Sub DeleteYellowRows() With ActiveSheet LstCell = [A65536].End(xlUp).Row Set MyRng = Range("A1:A" & LstCell) For Each MyCell In MyRng If MyCell.Interior.ColorIndex can then call the macro from the macros menu Alt + F8 from the main excel application window from here you can assign a keyboard shortcut to the macro from the options button. Hope this helps S keywords: To, delete, specific, color, index, row description: Hi, I tried to run the macro code below, but it does not even
Any formula to return the most frequent bin range? Excel Hi all , In a row i have : A1 = 450 B1 = 560 C1 = 500 D1 = 510 E1 = 445 F1 = 430 G1 returns the lower limit of the bin with the most occurrences: C3: = MODE(LOOKUP(A1:INDEX(1:1, COUNTA(1:1)), A3+ (ROW(INDEX(A:A, 1):INDEX(A:A, 1+CEILING(MAX(1:1)- A3, A4) / A4))-1)*A4)) This formula returns 450, 560, etc Diff is the cell where you have your difference, e.g. 50 = INDEX(Diff*(FLOOR(SMALL(Weights;1);Diff) / Diff-1+ROW(OFFSET( A1;0;0;CEILING(LARGE(Weights;1);Diff) / Diff-FLOOR(SMALL(Weights;1);Diff Diff+1;1))); MATCH(MAX(FREQUENCY(Weights;Diff*(FLOOR(SMALL(Weights;1);Diff) / Diff+ ROW(OFFSET(A1;0;0;CEILING(LARGE(Weights;1);Diff) / Diff-FLOOR(SMALL( Weights;1);Diff
changes, I want to clear the contents of COL P, Q R (in the same row) If a cell in COL Q changes, I want to clear the contents of COL O, P, R (again in the same row) I think I had the following working in Excel 2003, but its not working in Worksheet_Change(ByVal Target As Excel.Range) With Target Select Case .Column Case 15 'column O Application.EnableEvents = False Cells(.Row, "P").ClearContents Cells(.Row, "Q").ClearContents Cells(.Row, "R").ClearContents Application.EnableEvents = True Case 17 'column Q Application.EnableEvents = False Cells(.Row, "O").ClearContents Cells(.Row, "P").ClearContents Cells(.Row, "R").ClearContents Application