Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a print range from Excel to pdf file?

Status
Not open for further replies.

cogivina

Programmer
Jun 3, 2003
36
US
Hi,

I have macro in VBA that would print different range area selections from a worksheet in Excel.

With ActiveSheet.PageSetup
.PrintArea = "My_Print_Sel"
ActiveSheet.PrintOut
End with

I'd like to save My_Print_Sel into a pdf file. Please help.

Thanks.
 
You will need Adobe PDF distiller
There are several posts on this subject already in this forum if you do a search

Chance,

F, G + 1MSTG
 
we use PDF995 at work.

Distiller is not the easiest thing to follow (but i try).

there is a tide in the affairs of man that you Cnut ignore.................
 
I use the below marco to create the myPDF.pdf. I get this message when trying to open it. The error said: "Acrobat coult not open 'myPDF.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded). To create an Adobe PDF document, go to the source application. Then print the document to Adobe PDF". It works when I do manually from the Excel workbook. Would you point out what I did wrong here in my macro code. Thanks.
___________________________

Sub Macro5()
'
Dim PDFFileName As String

PDFFileName = "E:\myPDF.pdf"

MySheet.Range("MyRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=False, Collate:=True, PrToFileName:=PDFFileName

End Sub
___________________________
 
Have you taken a look at the links I attached. This would work exactly how you want it to.

Swi
 
Thanks, Swi for your quick response. Yes, I did. It required to have the pdfcreator installed from sourceforge.net. I was hoping that I can do it without the pdfcreator. Otherwise, it will require other my users to install it as well before they can use the macros.
 
Have you tried this ?
MySheet.Range("MyRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=[!]True[/!], Collate:=True, PrToFileName:=PDFFileName

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PH,

I got the run-time error '424' --- Object required.

Thanks.


Sub Macro5()
'
Dim PDFFileName As String
'
PDFFileName = "E:\myPDF.pdf"

MySheet.Range("MyRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=True, Collate:=True, PrToFileName:=PDFFileName

End Sub
 
What is MySheet and where is it defined/populated ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The MySheet is a range name and defined in the spread sheet. It is created by Insert-Name-Define-MySheet.
 
Hi PH,

I have 5 different ranges names in the spread sheet and they all have different setting for printing. My goal is trying to create a single pdf file containing all 5 print pages. So far I'm having problem with just one page. Hope you can help.
 
Hi,

I'm back. I changed MySheet to Sheets("Fact") then it worked. I though I did not have to define MySheet. I still get the error stated from above: "Acrobat coult not open.."

-----------
Sub Macro5()
'
Dim PDFFileName As String
'
PDFFileName = "E:\myPDF.pdf"

Sheets("Fact").Range("MyRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=True, Collate:=True, PrToFileName:=PDFFileName

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top