johnny51981
Active Member
- Joined
- Jun 8, 2015
- Messages
- 409
Hello:
I plagiarized the following VBA from a YouTube video that I found, and it gives me exactly what I am needing...however it is missing a piece that I hope can be solved here. I would appreciate any help, and please know...I am not very strong in VBA (yet).
I am needing to augment this code to only return file names that contain the words "WORK ORDER" and that are saved as a PDF file type.
I plagiarized the following VBA from a YouTube video that I found, and it gives me exactly what I am needing...however it is missing a piece that I hope can be solved here. I would appreciate any help, and please know...I am not very strong in VBA (yet).
I am needing to augment this code to only return file names that contain the words "WORK ORDER" and that are saved as a PDF file type.
VBA Code:
Option Explicit
Sub ListAllFiles()
ThisWorkbook.Sheets("Files").Select
Call ClearList
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Range("NTPFolder"))
Call GetFileDetails(objFolder)
End Sub
Function GetFileDetails(objFolder As Scripting.Folder)
Dim objFile As Scripting.File
Dim nextRow As Long
Dim objSubFolder As Scripting.Folder
nextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each objFile In objFolder.Files
Cells(nextRow, 1) = objFile.Name
Cells(nextRow, 2) = objFile.Path
Cells(nextRow, 3) = objFile.Size
Cells(nextRow, 4) = objFile.Type
Cells(nextRow, 5) = objFile.Attributes
nextRow = nextRow + 1
Next
For Each objSubFolder In objFolder.SubFolders
Call GetFileDetails(objSubFolder)
Next
End Function
Sub ClearList()
'
' ClearList Macro
'
'
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A2").Select
End Sub