Print sheets and table as one pdf file

No Luck

New member
Joined
Aug 22, 2013
Messages
1
Reaction score
0
Points
0
Originally posted on microsoft forum but no answer yet :help:

Hi Gang


I found code that prints specific named sheets from my workbook to pdf. Now I need to add a table from one of the sheets as a separate pdf page. The extra issue is that this additional table needs to print in landscape, fit to 1 page. The other sheets are fine as they are. This code does refer to the RDB_Create_PDF function but I don't think that needs to change.......

The excellent code that I am currently using to print the multiple sheets is:

Sub RDB_Worksheet_Or_Worksheets_To_PDF()
Dim FileName As String
Dim vaWorksheets As Variant
vaWorksheets = Array("Cover", "Summary", "Service", "DataChart")

If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If

'Call the function with the correct arguments
'Tip: You can also use Sheets("Sheet3") instead of ActiveSheet in the code(sheet not have to be active then)
' FileName = RDB_Create_PDF(ActiveSheet, "", True, True)

FileName = RDB_Create_PDF(Sheets(vaWorksheets), "", True, True)

'For a fixed file name and overwrite it each time you run the macro use
'RDB_Create_PDF(ActiveSheet, "C:\Users\Ron\Test\YourPdfFile.pdf", True, True)


If FileName <> "" Then
'Ok, you find the PDF where you saved it
'You can call the mail macro here if you want

Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End Sub


The table is called tblServiceData and is on the Service sheet.

Thanks in advance!
 
Code:
Sub exportToPdfsomeSheetsTo1pdf() 
' Sheets(Array("Sheet1", "Sheet3")).Select
Sheets.Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
    "C:\test\NewBook.pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    True
Sheets(1).Select
End Sub
 
try:
Code:
Sub RDB_Worksheet_Or_Worksheets_To_PDF()
Dim FileName As String
Dim vaWorksheets As Variant
With Sheets("Service").PageSetup
  .PrintArea = "tblServiceData[#All]"
  .Orientation = xlLandscape
End With

vaWorksheets = Array("Cover", "Summary", "Service", "DataChart")
Sheets(vaWorksheets).Select 'note you have to have the sheets selected.

If ActiveWindow.SelectedSheets.Count > 1 Then
  MsgBox "There is more then one sheet selected," & vbNewLine & _
         "be aware that every selected sheet will be published"
End If

FileName = RDB_Create_PDF(ActiveSheet, "", True, True)

If FileName <> "" Then
Else
  MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
         "Microsoft Add-in is not installed" & vbNewLine & _
         "You Cancelled the GetSaveAsFilename dialog" & vbNewLine & _
         "The path to Save the file in arg 2 is not correct" & vbNewLine & _
         "You didn't want to overwrite the existing PDF if it exists"
End If
End Sub
Note the reversion of this line to the original:
FileName = RDB_Create_PDF(ActiveSheet, "", True, True)

I think the pages get printed in the order they are in in the workbook, so you'd need to temporarily re-order the sheets if you want the Service sheet to be printed at the end of the pdf file.
I'm also assuming you don't also want to include all of the Service sheet in the pdf file, just the table.
 
Back
Top