Print all PDFs using VBA

greyangel23

New Member
Joined
Apr 23, 2024
Messages
3
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This is not an answer, I'm just trying to figure out what youve posted...
VBA Code:
Sub PDF_Loop()

   Dim FileSystem As Object, HostFolder As String
  
   HostFolder = InputBox("Where do you want to save the file?", "Save to...", "C:\Users\Username\Documents\")
  
   Set FileSystem = CreateObject("Scripting.FileSystemObject")
   DoFolder FileSystem.GetFolder(HostFolder)
  
      
End Sub
  
Sub DoFolder(Folder)
  
   Dim SubFolde,  NextRow As Long,File
  
   For Each SubFolder In Folder.SubFolders
       DoFolder SubFolder
   Next

   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
       Else
       End If
      
   Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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