greyangel23
New Member
- Joined
- Apr 23, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I am trying to use vba to print all pdf documents in a particular folder that holds sub folders. I found this code but I don't know what I need to add to it to print the documents.
Sub PDF_Loop()
Dim FileSystem As Object
Dim HostFolder As String
HostFolder = "C:\Users\Username\Documents\"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub
Sub DoFolder(Folder)
Dim SubFolder
Dim NextRow As Long
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
Dim File
For Each File In Folder.Files
' Operate on each file
If Right(File.Name, 4) = ".pdf" Then
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1) = File.Name
End If
Next
End Sub
Sub PDF_Loop()
Dim FileSystem As Object
Dim HostFolder As String
HostFolder = "C:\Users\Username\Documents\"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub
Sub DoFolder(Folder)
Dim SubFolder
Dim NextRow As Long
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
Dim File
For Each File In Folder.Files
' Operate on each file
If Right(File.Name, 4) = ".pdf" Then
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1) = File.Name
End If
Next
End Sub