Browse to Folder and Print PDF Files

damaniam1604

New Member
Joined
Sep 12, 2018
Messages
20
Hi,

I need to be able to browse to a folder in a variety of directories, select the desired folder and print all the PDF files within it. There are no subfolders to contend with. The folders contain only PDF's and I am good with it printing to the default printer.

I have looked over a few other posts, but nothing seems to fit my scenario. Probably because I don't know VBA that well in order to interpret and modify it. Any assistance would be greatly appreciated. Thanks in advance.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
See if this gets you started. It prints all the PDF files in the specified folder to the default printer. But note that this will work only if Print is an option in the File Explorer context menu when you right-click a PDF file.

VBA Code:
Public Sub Print_PDFs()

    Dim Sh32 As Object 'Shell32.Shell
    Dim ShFolderItem As Object 'Shell32.FolderItem
    Dim PDFsFolder As String
    
    PDFsFolder = "C:\path\to\folder\"
   
    Set Sh32 = CreateObject("Shell.Application")    
    For Each ShFolderItem In Sh32.Namespace(CVar(PDFsFolder)).Items
        If LCase(ShFolderItem.Path) Like "*.pdf" Then
            ShFolderItem.InvokeVerb "Print"
        End If
    Next

End Sub
The code could be modified to use Application.FileDialog(msoFileDialogFolderPicker) to browse for a folder, instead of specifying it in the code.
 
Upvote 0
Solution
The code worked perfectly once I specified the directory. Could you give me insight on where I would modify the code in order to browse to the folder?
 
Upvote 0
Replace the PDFsFolder line with:
VBA Code:
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select PDFs folder"
        .InitialFileName = ThisWorkbook.Path  'initial folder
        If .Show Then
            PDFsFolder = .SelectedItems(1) & "\"
        Else
            Exit Sub
        End If
    End With
 
Upvote 0

Forum statistics

Threads
1,214,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

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