VBS Convert Certain Page to PDF

klars12

New Member
Joined
Nov 19, 2015
Messages
4
Hi all, I know my way around Excels FORMULAS tab well enough but I am just starting to practice my VBS (it's like a foreign language that I can kind of tell what it says if it's written out, but no clue how to start from scratch!). Below is a macro I've used to update the date on a worksheet and save as PDF (thanks again to this forum for helping me with that) which is what I would like to use as the basis for this: I want to create a macro that will only create a certain PAGE on the worksheet, instead of everything. Is there a way to do this?

<>

Sub Save_Drywall_Estimate_Pdf()
' Saves active sheet as PDF file.


With Range("P104")
.Value = Date
.NumberFormat = "mmmm, d yyyy"
End With


Name = ThisWorkbook.Path & "\" & ActiveSheet.Range("AD3").Value & " - " & ActiveSheet.Name & " - " & _
Format(Now(), "mm.dd.yyyy") & ".pdf"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Option#1: If you know the page number that you'd like to print then you can use From and To parameters. Following prints just page 2 and 3 to a pdf.
Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False, _
From:=2, To:=3


Option#2: If you know the area that you want to print then you can call this method on Range instead of the sheet.
Code:
Range("A1:G15").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=True, OpenAfterPublish:=False
 
Upvote 0

Forum statistics

Threads
1,214,896
Messages
6,122,132
Members
449,066
Latest member
Andyg666

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