Problems with Printing to PDF using VBA...

hollifd

Board Regular
Joined
Apr 3, 2002
Messages
248
I am using the following code to print a pdf file:

Code:
ActiveWindow.SelectedSheets.PrintOut ActivePrinter:="_PDF WRITER on Ne00:", PrintToFile:=True, Collate:=True, PrToFileName:="C:\Temp\Sample1.pdf"

When I try to open the PDF file that was created with this code, I get an error that states:

Adobe Reader could not open Sample1.pdf because it is either not a supported file type or the file has been damaged.

When I manually print the sheet and choose the PDF writer and select a filename, everthing works fine.

Does anyone have some items for me to look at for solving this problem?

Thanks,

David
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
More Information...

I can use sendkeys to fill out the path and filename on the PDF Writer window that appears when running the following code and everything works OK. I would prefer to not use SendKeys if at all avoidable since I am not really that knowledgeable about SendKeys.

Code:
ActiveWindow.Selectedsheets.PrintOut  ActivePrinter:="_PDF WRITER on Ne00:"

Only when I try to specify the PrintToFile and PrToFileName paramters using VBA does the PDF file get corrupted so that it cannot be opened.

Still looking for any and all ideas.

Thanks,

David
 
Upvote 0
Thanks Juan Pablo González,

Yes. I saw that too.

I have found another PDF writer printer option that is on our company's system and it seems to work correctly with this code:

Code:
ActiveWindow.SelectedSheets.PrintOut ActivePrinter:="\\srv2Win2PDF", PrintToFile:=True, PrToFileName:="C:\Temp\Dummy.pdf"

The PDF writer that I am now using is WIN2PDF.

Thanks again for the help.

David
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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