Macro to select File to Print

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have the following code that allows a user to select a PDF File to Print. Once selected, the PDF File opens and the user selects the Print Icon, Clicks on Print and it prints

I need the code amended that after printing a message box will appear "Do you need another copy, yes/No ? If Yes then select Print or if user selects No , then close the PDF file

It would be appreciated if someone could kindly amend my code


Code:
 Sub PrintSelectedPDFFile()
    Dim filePath As String
    
    ' Open file dialog to select PDF file
    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Select PDF file"
        .Filters.Clear
        .Filters.Add "PDF files", "*.pdf"
        .InitialFileName = "C:\pull"
        .AllowMultiSelect = False
        
        If .Show = -1 Then ' if the user selects a file
            filePath = .SelectedItems(1)
        Else
            Exit Sub ' user canceled selection
        End If
    End With
  
    ' Print the selected file using default application
    If Len(filePath) > 0 Then
        ShellExecute 0, "open", filePath, vbNullString, vbNullString, vbNormalFocus
        
    End If
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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