Howard Cohen
Member
Members
Forum Posts: 56
Member Since:
December 8, 2016
December 8, 2016
Offline
I have many sub-folders within c:\accnts for eg TBBR1, TBKWNT,TBBORG
I would like my macro , which list alls the sub-folders within C:\accnts, but lists these on a sepertate workbook and not within the workbook containing the macro
I would also like to the folder to be set to C:\Accnts so no need to select the folder
The Sub-folders are for eg the ones listed below
C:\accnts\TBBR1
C:\accnts\TBKWNT
C:\accnts\TBBORG Etc
[code] Sub Extract_subFolder_Names() Sheets("").Select Application.ScreenUpdating = False Dim xPath As String Dim xWs As Worksheet Dim fso As Object, j As Long, folder1 As Object With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Choose the folder" .Show End With On Error Resume Next xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\" Application.Workbooks.Add Set xWs = Application.ActiveSheet xWs.Cells(1, 1).Value = xPath xWs.Cells(2, 1).Resize(1, 5).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified") Set fso = CreateObject("Scripting.FileSystemObject") Set folder1 = fso.getFolder(xPath) getSubFolder folder1 xWs.Cells(2, 1).Resize(1, 5).Interior.Color = 65535 xWs.Cells(2, 1).Resize(1, 5).EntireColumn.AutoFit Application.ScreenUpdating = True End Sub Sub getSubFolder(ByRef prntfld As Object) ChDir "C:\accnts\" Dim SubFolder As Object Dim subfld As Object Dim xRow As Long For Each SubFolder In prntfld.SubFolders xRow = Range("A1").End(xlDown).Row + 1 Cells(xRow, 1).Resize(1, 5).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified) Next SubFolder For Each subfld In prntfld.SubFolders getSubFolder subfld Next subfld End Sub [/code]
Your assistance in this regard is most appreciated
I have also posted on Macro to extract list of sub-folders within a folder | MrExcel Message Board
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Velouria, Riny van Eekelen
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
1 Guest(s)
Top Posters:
Catalin Bombea: 1939
SunnyKow: 1432
Anders Sehlstedt: 925
Purfleet: 415
Frans Visser: 349
Hans Hallebeek: 343
David_Ng: 312
lea cohen: 248
Jessica Stewart: 219
A.Maurizio: 216
Newest Members:
Hiroyuki Murai
Mark Allen
Yves Gagnon
PATRICK WALTER
Carley Brice
Ash Rahman
Christelle Lamprecht
Wei Kwok Tey
Partha Pratim Nandy
Inge Rousseau
Forum Stats:
Groups: 3
Forums: 25
Topics: 7087
Posts: 31062
Member Stats:
Guest Posters: 49
Members: 34503
Moderators: 2
Admins: 3
Administrators: Mynda Treacy, Philip Treacy, Jessica
Moderators: Velouria, Riny van Eekelen
© Simple:Press —