Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a sub routine to print an excel worksheet as a PDF file. This works on my computer using Office 365 but does not work when I run the program on a laptop which has Office 2003.
I have successfully printed the worksheet manually using "Microsoft Print To PDF" on BOTH machines. The laptop creates the file but it does not have any content and cannot be opened. It has a size of zero bytes but if created manually it is 288KB.
Anybody have any ideas what is going on?

What I have tried:

The code I have written is as follows;
Private Sub SaveWorksheetAsPDF(Title As String, Path As String)
        Dim FileName As String = "\ResultsSheet" & Title & ".pdf"
        Dim totalFileName As String = Path & FileName
        'Print the document to PDF
        oSheet.PrintOut(copies:=1, Preview:=False, ActivePrinter:="Microsoft Print To PDF", PrToFileName:=totalFileName, PrintToFile:=True)

    End Sub
Posted
Updated 26-Oct-16 11:02am

1 solution

I have investigated further and have found that the "Microsoft Print To PDF" printer
does not like commas in the filename.
I need to change my code so that it does not create commas. Title is the output from a DateTimePicker and produces an output like "Wednesday, October 26, 2016".
Do not understand why it works on my desktop and not on the laptop but at least I have a way forward.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900