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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,223,702
Messages
6,173,936
Members
452,539
Latest member
delvey

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