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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel sheets to PDF 1

Status
Not open for further replies.

Donatumw

Instructor
Jul 2, 2007
3
US
I have an Excel file with 5 sheets. Trying to get all 5 sheets to go to PDF. It seems that only one sheet will go. I read where this is still not possible. I have Acrobat 7 professional.

I tried the vba code here but got errors.

All help greatly appreciated.
This is my first post so I hope it's ok.
Thanks,
Don
 




What line of code did you get an error on?

Please post ALL the code upt to that point, please.

Skip,

[glasses] [red][/red]
[tongue]
 
Sub makepdf()
'
' makepdf Macro
' Macro recorded 7/2/2007 by HP Authorized Customer
'Using Bits, Pieces and tips from all across the forum, this is the
'simple code that finally did it for me :

'SET DEFAULT PRINTER TO ADOBE FOR PDF REPORTS
Set Application.Printer = Application.Printers("Adobe PDF")

'PRINT to PDF - (To Include Additional Excel Sheets on the PDF, Simply
'add the Name of the Excel Sheet in Both the Arrays Below)

Dim ObjXL As Object
Set ObjXL = CreateObject("Excel.Application")

ObjXL.Workbooks.Open ("dontest")

'SELECT REQUIRED EXCEL SHEETS FOR PRINTING TO PDF

syntax error occured on the next line.
 
Have a look at the line continuation character: _

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here is all the code. I realized you could not see the code after I changed it. Sorry

Sub makepdf()
'
' makepdf Macro
' Macro recorded 7/2/2007 by HP Authorized Customer
'Using Bits, Pieces and tips from all across the forum, this is the
'simple code that finally did it for me :

'SET DEFAULT PRINTER TO ADOBE FOR PDF REPORTS
Set Application.Printer = Application.Printers("Adobe PDF")

'PRINT to PDF - (To Include Additional Excel Sheets on the PDF, Simply
'add the Name of the Excel Sheet in Both the Arrays Below)

Dim ObjXL As Object
Set ObjXL = CreateObject("Excel.Application")

ObjXL.Workbooks.Open ("dontest")

'SELECT REQUIRED EXCEL SHEETS FOR PRINTING TO PDF

ObjXL.ActiveWorkbook.Sheets(Array("sheet1", "sheet2",
"sheet3")).Select

'PRINT THEM SUCKERS to A SINGLE PDF;-)

ObjXL.ActiveWorkbook.Sheets(Array("sheet1", "sheet2",
"sheet3")).PrintOut , collate:=True

'Works Great on my Windows XP !

'If the Set Application.Printer code generates an error for you , then
'you can easily set the default printer to Adode manually - Click Start
'--> Printers and Faxes --> Right Click on Adobe -->Set as Default

'Hope this will help at least some people :)

'
End Sub
 
Excel file with 5 sheets. Trying to get all 5 sheets to go to PDF
Why not simplify the code like this ?
ObjXL.Workbooks.Open "dontest"
ObjXL.ActiveWorkbook.PrintOut

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top