Forum Discussion
sayedy1295
Sep 25, 2024Copper Contributor
Vba
Hey all I have my excel workbook with a main sheet that has the table of contents for each content it is hyperlinked with other sheets . i want to make a vba code to print my workbook as a pdf...
KhaledDardiri
Sep 28, 2024Copper Contributor
Sure, insert a new module and paste the following code into it:
Option Explicit
Sub SaveAsPDFWithHyperlinks()
Dim ws As Worksheet
Dim pdfPath As String
Dim pdfFileName As String
' Set the worksheet you want to save as PDF
Set ws = ThisWorkbook.Sheets("Main Sheet") ' Change "Main Sheet" to your sheet name
' Set the path and file name for the PDF
pdfPath = ThisWorkbook.Path & "\"
pdfFileName = "YourFileName.pdf" ' Change to your desired file name
' Export the sheet as PDF
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath & pdfFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub