Ottsel
Board Regular
- Joined
- Jun 4, 2022
- Messages
- 174
- Office Version
- 365
- Platform
- Windows
I've been using a bat file to create an updated directory list of all my file names within a certain drive and folder, then I use another macro to extract and filter the data. The issue is for some reason I have to be within that folder, use that bat file to generate the list (which it disguises itself as excel file) to have it correctly make the list.
The Bat file:
Then upon opening the extractlist it'll appear as such:
It puts everything in column A, which is fine and it contains over 5000 rows of data. This method is fast, but the main issue is if you forget to update the directory and use the other macro you encounter errors, which is unfortunate, as it takes a while for it to run everything. I attempted to have VBA run the bat file for me, but again you have to be within the folder, click it, generate the list while in the Records folder for it to work.
If you know a way to get a list to generate all the folder names, sub-folders within the Drive and Folder destination and files I would greatly appreciate any insight on this.
Here's the VBA code I use to extract the list, it generates the files on my desktop instead of the G drive > Records folder.
The Bat file:
Rich (BB code):
G:
CD Records
dir /b /s >extractlist.xls
Then upon opening the extractlist it'll appear as such:
It puts everything in column A, which is fine and it contains over 5000 rows of data. This method is fast, but the main issue is if you forget to update the directory and use the other macro you encounter errors, which is unfortunate, as it takes a while for it to run everything. I attempted to have VBA run the bat file for me, but again you have to be within the folder, click it, generate the list while in the Records folder for it to work.
If you know a way to get a list to generate all the folder names, sub-folders within the Drive and Folder destination and files I would greatly appreciate any insight on this.
Here's the VBA code I use to extract the list, it generates the files on my desktop instead of the G drive > Records folder.
VBA Code:
Sub UpdateDirectory_test()
Dim wb As Workbook
Dim sourcePath As String
Dim extractList As String
sourcePath = "G:\Records\"
extractList = sourcePath & "extractlist.xls"
Dim oldWarning As Long
oldWarning = Application.DisplayAlerts
Application.DisplayAlerts = False
Shell sourcePath & "Extract Jobcard List.bat"
Application.Wait (Now + TimeValue("0:00:03"))
Application.DisplayAlerts = oldWarning
Set wb = Workbooks.Open(extractList)
wb.Sheets(1).Range("A1:A" & wb.Sheets(1).Range("A1").End(xlDown).row).Copy _
Destination:=ThisWorkbook.Sheets("Directory").Range("A1")
wb.Close False
End Sub