Save As PDF Error Handeling

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
I am trying to use the code below to check and see if the user is able to publish documents as a PDF. Looks like it should work but each time I run it the script keeps going to the last error handler.
When I try and publish the document manually by doing:
SaveAs >
PDF or XPS >
It works just fine. What am I doing wrong here?
Code:
On Error GoTo ErrorHandler
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Documents and Settings\" & Application.UserName & "\Local Settings\Temp\QAM-Report.pdf", Quality:=xlQualityMinimum, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        False
   
ErrorHandler:
If Err.Number = 1004 Then
    Dim oShell As Object
    Dim iResponse As Integer
    Set oShell = CreateObject("Wscript.Shell")
    iResponse = MsgBox("Sorry it looks as though you don't have a way to save this document as a PDF so I can't email it.  You probably just need to download an ""Add-in"" for Excel" & vbNewLine & vbNewLine _
    & "Do you want to download the ""Add-in""?", vbYesNo, "We Gotta Problem!")

    If iResponse = vbYes Then
        oShell.Run ("http://download.microsoft.com/download/f/4/b/f4bfd843-a0b6-4031-aa98-0a3db7403d0f/SaveAsPDFandXPS.exe")
        Exit Sub
    Else
    Exit Sub
    End If
Else
MsgBox "There is a problem with your computer that will not allow this message to be sent.  Call the Office"
Exit Sub
End If
Resume Next
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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