PDF Code error

JVID

New Member
Joined
Jan 9, 2013
Messages
39
I found this code on the below website and I am getting a syntax error.Any idea? Saving Excel Worksheets as PDFs Using Macros
Code:
Sub RDB_Worksheet_Or_Worksheets_To_PDF() 
    Dim FileName As String 
    If ActiveWindow.SelectedSheets.Count > 1 Then 
        MsgBox "There is more than one sheet selected," & vbNewLine & _ 
               "and every selected sheet will be published." 
    End If 
    'Replace numSheets with the number of worksheets that will be saved as PDF 
    For x = 1 To numSheets 
        Sheets("WorksheetNames").Select 
        ThisSheet = ActiveSheet.Range("A" & x).Value 
        Sheets(ThisSheet).Select 
        'Call the function with the correct arguments 
        FileName = RDB_Create_PDF(Sheets(ThisSheet), "C:\test\" & ActiveSheet.Name & ".pdf", True, True) 
        If FileName <> "" Then 
            'Ok, you find the PDF where you saved it 
        Else 
            MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _ 
               "Microsoft Add-in is not installed" & vbNewLine & _ 
               "You Canceled the GetSaveAsFilename dialog" & vbNewLine & _ 
               "The path to Save the file in arg 2 is not correct" & vbNewLine & _ 
               "You didn't want to overwrite the existing PDF if it exist" 
        End If 
    Next x 
End Sub 
Function RDB_Create_PDF(Myvar As Object, FixedFilePathName As String, _ 
                        OverwriteIfFileExist As Boolean, OpenPDFAfterPublish As Boolean) As String 
    Dim FileFormatstr As String 
    Dim Fname As Variant 
    'Test If the Microsoft Add-in is installed 
    If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _ 
         & Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") <> "" Then 
        If FixedFilePathName = "" Then 
            'Open the GetSaveAsFilename dialog to enter a file name for the pdf 
            FileFormatstr = "PDF Files (*.pdf), *.pdf" 
            Fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _ 
                                                  Title:="Create PDF") 
            'If you cancel this dialog Exit the function 
            If Fname = False Then Exit Function 
        Else 
            Fname = FixedFilePathName 
        End If 
        'If OverwriteIfFileExist = False we test if the PDF 
        'already exist in the folder and Exit the function if that is True 
        If OverwriteIfFileExist = False Then 
            If Dir(Fname) <> "" Then Exit Function 
        End If 
        'Now the file name is correct we Publish to PDF 
        On Error Resume Next 
        Myvar.ExportAsFixedFormat _ 
                Type:=xlTypePDF, _ 
                FileName:=Fname, _ 
                Quality:=xlQualityStandard, _ 
                IncludeDocProperties:=True, _ 
                IgnorePrintAreas:=False, _ 
                OpenAfterPublish:=False 
        On Error GoTo 0 
        'If Publish is Ok the function will return the file name 
        If Dir(Fname) <> "" Then RDB_Create_PDF = Fname 
    End If 
End Function
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You did not get a reply until now.
Most probably, because you don't indicate what line your error is on.
Did you go through the macro and edit the code to match your own situation?
 
Upvote 0

Forum statistics

Threads
1,216,880
Messages
6,133,210
Members
449,788
Latest member
sutthipv

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