Results 1 to 3 of 3

Thread: Print sheets and table as one pdf file

  1. #1

    Print sheets and table as one pdf file



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Originally posted on microsoft forum but no answer yet

    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!

  2. #2
    Acolyte patel's Avatar
    Join Date
    Feb 2014
    Location
    Italy
    Posts
    59
    Articles
    0
    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

  3. #3
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,480
    Articles
    0
    Excel Version
    365
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •