Saving PDF Problem

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
I am using the following line of code to save a document as a PDF:
Code:
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

I works perfect if the user have a printer installed but I just found out if the user does not have a printer installed I get the following error code:

Saving-PDF-Error.jpg


Is there any way around this?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Not to state the obvious but if you are trying to use a device that's not present on a certain computer there are 2 ways to solve that problem.

1: install the PDF writing software (pfd printer)

2: exempt those computers by doing a check in your code so that if the PDF printer is not available they get a message like:

to use this function you need application X to be found at location Y etc.

Sincerely,
 
Upvote 0
That would be perfect. Maybe something that checks the users machine for a PDF Printer before getting too far into the code.

If they don't have PDF Printer maybe a MsgBox telling them what to do, where to download PDF Printer, ect...

If PDF Printer detected then continue with the rest of the code.

How would the code for a check system like this look?
 
Upvote 0
from excel help:

Code:
Sub InitializeMatrix(Var1, Var2, Var3, Var4)
    On Error GoTo ErrorHandler
    . . .
    Exit Sub
ErrorHandler:
    . . .
    Resume Next
End Sub

meaning that if you put the On Error GoTo ErrorHandler before the pdf write function and and make a ErrorHandler: sub with the appropriate meaage you're covered.

Sincerely,
 
Upvote 0
If i include the following:
Code:
On Error GoTo ErrorHandler
    Exit Sub
ErrorHandler:
    MsgBox "Sorry"
    Resume Next

        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
I get nothing the code just stops. Is this the right way to write this?
 
Upvote 0
Code:
Sub InitializeMatrix(Var1, Var2, Var3, Var4)
    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
    Exit Sub
ErrorHandler:
   MsgBox "Sorry you need application X to perform the operation"
    Resume Next
End Sub

presumably ...

Sincerely,
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

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