Export Excel Sheet to PDF available for printing

littlejilly

Board Regular
Joined
Sep 8, 2011
Messages
168
Hello All,

I have an excel workbook with several sheets in it. On the Summary tab, I have added in an ActivX command button in hopes that I can correctly write code that will copy the content seen on the sheet (values only) and copy it to a pdf and open the file.

I have used the following code but I am coming up with an error:

Rich (BB code):
Private Sub PrintPDF_Click()

Dim fileName As String

Sheets("Summary").Select
'set the path and file name
fileName = "C:WINDOWSDesktopsheet1.PDF"
'Enters the name and path of the PDF file when the PrintFileAs dialog box is opened
SendKeys fileName & "{ENTER}", False
'prints the file
Worksheets(1).PrintOut ActivePrinter = "Acrobat PDFWriter on LPT1:"

end sub

I have colored the line in red where I receive the following error:

Run-time error '1004': The number must be between 1 and 32767. Try again by entering a number in this range.

I am not even sure that this is the correct code. I dont necessaily need to print automatically but if I could at least get the pdf to open with a copy of the summary tab, that would be most helpful.

Any suggestions are greatly appreciated.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Change printer "Acrobat PDFWriter on LPT1:" to another printer and test the macro
I think the 1004 error is from the printer driver not from excel
 
Upvote 0
Thanks for your response. It was most helpful. I was able to edit the code so that it prints to PDF file. Any idea how to automatically name the file and have it save to the desktop, lets say "Summary" Also, might you have a suggestion on how to add in code so that it scales down the excel sheet and prints to a landscape direction pdf?

THank you again
 
Upvote 0

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

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