Amend VBA Code to Save 1x Page Only

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

I have the below VBA code which successfully saves the worksheet to PDF. However, I would like to save only a particular page of the worksheet. Is this possible?
In the example below, I would like it to save page 1 of 21 pages. Which is also cells A1:J54

Thank you!

VBA Code:
Sub S4_Shareholder_1()
   
    Dim wsA As Worksheet
 Dim wbA As Workbook
 Dim strTime As String
 Dim strName As String
 Dim strPath As String
 Dim strFile As String
 Dim strPathFile As String
 Dim myFile As Variant
 Dim blnWasSheetHidden As Boolean
 On Error GoTo errHandler

 Set wbA = ActiveWorkbook
 Set wsA = Sheet76

 'get active workbook folder, if saved
 strPath = wbA.Path
 If strPath = "" Then
 strPath = Application.DefaultFilePath
 End If
 strPath = strPath & ""

 strName = wsA.Range("D14").Value _
 & " - " & wsA.Range("B6").Value _
 & " " & Format(wsA.Range("I11"), "dd-mmm-yy")

 'create default name for savng file
 strFile = strName & ".pdf"
 strPathFile = strPath & strFile

 'use can enter name and
 ' select folder for file
 myFile = Application.GetSaveAsFilename _
 (InitialFileName:=strName & ".pdf", _
 FileFilter:="PDF Files (*.pdf), *.pdf", _
 Title:="Select Folder and FileName to save")

 'export to PDF if a folder was selected
 If myFile <> "False" Then
 If wsA.Visible = xlSheetHidden Then
    wsA.Visible = xlSheetVisible
    blnWasSheetHidden = True
End If
 wsA.ExportAsFixedFormat _
 Type:=xlTypePDF, _
 Filename:=myFile, _
 Quality:=xlQualityStandard, _
 IncludeDocProperties:=True, _
 IgnorePrintAreas:=False, _
 OpenAfterPublish:=False
 If blnWasSheetHidden = True Then
    wsA.Visible = xlSheetHidden
 End If
 'confirmation message with file info
 MsgBox "PDF file has been created: " _
 & vbCrLf _
 & myFile
 End If

exitHandler:
 Exit Sub
errHandler:
 MsgBox "Could not create PDF file"
 Resume exitHandler
 End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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