Save print range to pdf file using command button

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,845
Morning,
I wish to save a range from my worksheet in the pdf file type.
The code below works fine with no errors etc but when i view the saved pdf i can see my command buttons which on the worksheet are in columns D & E
When i press the command button i only wish to save what i can see in the range F2:P61 so anything outside that range is not saved.

The code in use is as follows,

Code:
Private Sub CommandButton1_Click()    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES.pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "INVOICE " & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly
        Exit Sub
    End If
    
    With ActiveSheet
        .PageSetup.PrintArea = "$F$2:$P$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        MsgBox "INVOICE " & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly


        ActiveWorkbook.Save
    End With


End Sub
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,845
All sorted.
Not sure why but i thought i would change the range in the code to see what happened.
Changing it from F2:P61 to G3:O61 worked.

Have a nice day
 

Forum statistics

Threads
1,082,612
Messages
5,366,606
Members
400,906
Latest member
incanus

Some videos you may like

This Week's Hot Topics

Top