Save Multiple Ranges in a PDF Document.

The_Steward

Board Regular
Joined
Nov 26, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hey,

I want to save two different ranges into a PDF document. One range for each page.

The first range is Worksheets("Data Storage").Range("$N$4:$P$20") = Range for First Page

The second range is Worksheets("Data Storage").Range("$Z$32:$AG$97") = Range for Second Page (The Range in Macro Below)

The Macro below works for one range, but can't seem to make it work for an array yet.

VBA Code:
Sub SaveAsPDF()

    Dim filePath As Variant
    Dim exportRange As Range
    
    'Set the export range to the specified array in the "Data Storage" worksheet
    Set exportRange = Worksheets("Data Storage").Range("$Z$32:$AG$97")
    
    'Open the save dialog box
    filePath = Application.GetSaveAsFilename(fileFilter:="PDF Files (*.pdf), *.pdf", Title:="Save As PDF")
    
    'Check if user has cancelled the dialog box
    If filePath = False Then Exit Sub
    
    'Save the export range as PDF file
    exportRange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filePath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    
    
    'Open the PDF file if it was saved successfully
    If Dir(filePath) <> "" Then
        ActiveWorkbook.FollowHyperlink filePath
    End If

End Sub

I also want to only include first page when a Checkbox in one of userforms is clicked.

The name of the Checkbox in the userform is CheckBox_AddBDetails
The Name of the Userform is SOSCustomiser

Any help is greatly appreciated.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Change exportRange to:
VBA Code:
    Set exportRange = Worksheets("Data Storage").Range("$N$4:$P$20,$Z$32:$AG$97")
 
Upvote 0
Solution

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top