Excel VBA Macro: Save Selected Range as PDF (and Center on Page). In this video, we go over how to write code that allows us to select a range on a worksheet and only use that selected range to create a pdf, save the pdf, and align the range in the center of the page. We also go over how to include icons from excel in our new pdf.
Code:
Sub save_range_as_pdf()
Dim pdf_range As Range
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
Set pdf_range = ws.Range("B2:C14")
ws.PageSetup.CenterHorizontally = True
pdf_range.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Users\greggowaffles\Documents\" & _
"Youtube Videos\Test\Cookie Sales Reports\" & _
"Cookie Sales Report " & _
ws.Range("B11").Text & ".pdf", OpenAfterPublish:=True
End Sub
#ExcelVBA #ExcelMacro