none
How do I select multiple ranges across multiple sheets within the same workbook and print to PDF using VBA? RRS feed

  • Question

  • Unfortunately, I'm still extremely basic with VBA and any help would be much appreciated. I have figured out a few simple moves, but am now struggling with expanding on these.

    Essentially, I am printing a specific range within a worksheet to PDF and automatically saving it in a folder defining the file name at the same time. I understand how to do this for a single range:

    Sub CommandButton1_Click()
        Application.ScreenUpdating = False
          Dim fileName As String
      fileName = "C:\Temp\Export.pdf"
        Sheet1.Range("A1:D13").ExportAsFixedFormat Type:=xlTypePDF, _
                fileName:="C:\U...\" & ActiveSheet.Range("A1").Value & Format(Now(), "_MMDDYYYY_hhmm") & ".pdf", _
                OpenAfterPublish:=True
        Application.ScreenUpdating = True
    End Sub

    What I'm trying to achieve is adding a (different) range on e.g. sheet 13 and yet another range on e.g. sheet 17, with all ranges printed to the same PDF.

    Any ideas?

    Thank you!

    Friday, October 11, 2019 5:06 PM