Need to print current PDF advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,

The code below is 99% complete apart from printing the newly created PDF
Below is the current working code in use.

It does what i require BUT whenYES is selected on the MsgBox i currently have in place ("Hi")
This is where i would like to Hi with the code to print the current PDF

Rich (BB code):
Private Sub Generate_Pdf_Click()
    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\FIONA RECEIPTS\" & "FIONA " & Range("J4").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GENERATED PDF INVOICE" & vbNewLine & vbNewLine & "FIONA " & Range("J4").Value & vbNewLine & vbNewLine & "WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly, "GENERATE PDF FILE MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .PageSetup.PrintArea = "$F$2:$K$60"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        pdf = MsgBox("GENERATED PDF INVOICE" & vbNewLine & vbNewLine & "FIONA " & Range("J4").Value & vbNewLine & vbNewLine & "WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE")
          
    End With
        Dim answer As Integer
        answer = MsgBox("DO YOU WISH TO PRINT THIS INVOICE ?", vbYesNo + vbInformation, "PRINT PDF FIONA MESSAGE")
    If answer = vbNo Then
        Range("J4").Value = Range("J4").Value + 1
        Range("G27").Select
    Exit Sub
    Else
    MsgBox ("Hi")
        Range("J4").Value = Range("J4").Value + 1
        Range("G27").Select
    End If
End Sub

Many Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Put on top of the vba module that contains your Sub Generate_Pdf_Click the following declaration:
Code:
#If VBA7 Then
   Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
#Else
   Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
        ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If


Going to your code, I seem that the variable strFileName contains the full Path & Name of the file to be opened; thus you just have to replace the line MsgBox ("Hi") with
Code:
    lngX = ShellExecute(vbNull, "Open", strFileName, "", "", vbMaximizedFocus)
This will open the pdf file using the default application for pdf format

Bye
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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