Having trouble with VBA code trying to save copy of workbook PDF

sspreyer

New Member
Joined
Jul 31, 2013
Messages
30
Hi everyone would like to save copy of the workbook in PDF every time someone save the work and put the PDF in a different location
I have some code but I'm getting error with see code below


Thanks in advance
Cheers
Shane
Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)


    Dim Filename As String
    Dim Filepath As String
    
        Filepath = "C:\Users\Shane\Documents\"
        Filename = Filepath & ThisWorkbook.Name


        If Success Then
            With ThisWorkbook.ExportAsFixedFormat _ ' this line highlights and i get error message ("compile error expected file or variable")
                (Type:=xlTypePDF, _
                 Filename:=Filename, _
                 Quality:=xlQualityStandard, _
                 IncludeDocProperties:=True, _
                 IgnorePrintAreas:=True, _
                 OpenAfterPublish:=False)
            End With
        End If
        
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try

Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)


    Dim Filename As String
    Dim Filepath As String
    
        Filepath = "C:\Users\Shane\Documents\"
        Filename = Filepath & ThisWorkbook.Name


        If Success Then
            ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Filename, _
                 Quality:=xlQualityStandard, _
                 IncludeDocProperties:=True, _
                 IgnorePrintAreas:=True, _
                 OpenAfterPublish:=False
        End If
        
End Sub
 
Upvote 0
Try

Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)


    Dim Filename As String
    Dim Filepath As String
    
        Filepath = "C:\Users\Shane\Documents\"
        Filename = Filepath & ThisWorkbook.Name


        If Success Then
            ThisWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Filename, _
                 Quality:=xlQualityStandard, _
                 IncludeDocProperties:=True, _
                 IgnorePrintAreas:=True, _
                 OpenAfterPublish:=False
        End If
        
End Sub
thanks alot worked great legend!!! also is there way i could make this only save active sheet not whole workbook to pdf

cheers
shane
 
Last edited:
Upvote 0
If you are able to add new programs on your computer, you can install a free pdf printer driver like Bullzip, and then you can print whatever part of a book/sheet to a pdf. Just another option...
 
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

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