Extract .xls or .xlsm files within a folder and sub-folder

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have a macro to extract excel files from c:\PULL as well as sub-folder within pull that are .xls or .xlsm


The .xls or being extracted but not the .xlsm if there is an xlsm file


Kindly amend my code below


Code:
 Sub List_Man_Acc_FileNames()

Sheets("file names").Range("A1:C150").ClearContents
Application.ScreenUpdating = False
Sheets("file names").Range("A1:C1").Value = Array("File Name", "Created", "Last Modified")

LoopController ("C:\pull")
Sheets("file names").Columns.AutoFit

End Sub

Private Sub LoopController(sSourceFolder As String)
'This will loop into itself, first processing the files in the folder
'then looping into each subfolder deeper and deeper until all folders processed
Dim Fldr As Object, FL As Object, SubFldr As Object

    Call ListFilesinFolder(sSourceFolder & Application.PathSeparator)

    Set Fldr = CreateObject("Scripting.FileSystemObject").GetFolder(sSourceFolder)
    For Each SubFldr In Fldr.SubFolders
        LoopController SubFldr.path
    Next

End Sub

Sub ListFilesinFolder(MyPath As String)
Dim FSO As Object, f As Object, FLD As Object, NR As Long

NR = Sheets("file names").Range("A" & Rows.Count).End(xlUp).Row
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FLD = FSO.GetFolder(MyPath).Files

For Each f In FLD
    If InStr(f.Name, "ACCNTS(P)") > 0 And Right(f.Name, 4) = ".xls" Or InStr(f.Name, "ACCNTS(P)") > 0 And Right(f.Name, 4) = ".xlsm" Then
        NR = NR + 1
        Sheets("file names").Range("A" & NR).Value = f.Name
        Sheets("file names").Range("B" & NR).Value = f.DateCreated
        On Error Resume Next
        Sheets("file names").Range("C" & NR).Value = f.DateLastModified
        On Error GoTo 0
    End If
Next f

End Sub


Your assistance is most appreciated
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,214,551
Messages
6,120,159
Members
448,948
Latest member
spamiki

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