VBA & Macro Problems

Export Excel Worksheet to PDF Preserving Hyperlinks using VBA

Olivia MillerOlivia Miller Nov 10, 2026 869 views

Question details

The user wants to automate the process of exporting a specific worksheet to a PDF file using VBA, while ensuring that all hyperlinks within the sheet remain active and clickable in the resulting PDF.

Export Excel Worksheets to PDF While Preserving Hyperlinks Using VBA
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Automating document generation and reporting where active hyperlinks must be retained in the final PDF output without manual conversion.
Observed behavior
The goal state is to execute a macro that saves the specified worksheet as a PDF in the same directory as the workbook, keeping all hyperlinks fully functional.
Before you start

Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) and verify that the Developer tab is enabled on your ribbon to access the VBA Editor.

Solution 1Recommended

Use ExportAsFixedFormat in a VBA Module

Utilize the native ExportAsFixedFormat method in VBA to automate PDF creation while embedding document properties that keep hyperlinks active.

The ExportAsFixedFormat method is the most reliable way to convert worksheets to PDF via VBA while retaining document properties and hyperlinks.

The provided macro will automatically generate the PDF in the exact same directory as your original workbook and open it upon completion.

1
Open the VBA Editor

Open your workbook and press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) Editor.

2
Insert a New Module

In the VBA Editor, click on 'Insert' in the top menu bar, and select 'Module' to create a new blank standard module.

3
Paste the VBA Code

Paste the following script into the module window: Sub SaveAsPDFWithHyperlinks() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Main Sheet") ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\YourFileName.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True End Sub

4
Customize the Variables

Modify the text "Main Sheet" to match the exact name of the worksheet you want to export. Then, change "YourFileName.pdf" to your desired output file name.

5
Run the Macro

Press F5 or click the green 'Run' button in the toolbar to execute the macro. The PDF will be generated with preserved hyperlinks and open automatically.

Use ExportAsFixedFormat in a VBA Module
Hyperlinks Preserved: Setting 'IncludeDocProperties:=True' in the VBA code ensures that your hyperlinks are successfully carried over and remain clickable in the final PDF document.
Advanced Macro Support

Automate PDF Exports Effortlessly with WPS Office

WPS Spreadsheet provides a robust VBA and Macro environment, allowing you to run your PDF export scripts seamlessly. It is a lightweight, fully compatible suite designed to handle advanced automated workflows effortlessly.

  1. 1. Install WPS Office: Download and install WPS Office Free on your computer.
  2. 2. Open Your Workbook: Launch WPS Spreadsheet and open your Macro-Enabled Workbook (.xlsm).
  3. 3. Access the VBA Editor: Navigate to the Tools tab and click on 'Macro', or simply press Alt + F11 to open the built-in VBA Editor.
  4. 4. Run Your Script: Insert a new module, paste your PDF export code, and run it directly to generate your interactive PDF.
Fully compatible with Microsoft Excel VBA macros and standard scripts.Natively supports exporting worksheets to PDF with active hyperlinks via VBA.Lightweight installation with a user-friendly, familiar ribbon interface.Cost-effective and highly efficient alternative for spreadsheet automation.
microsoft office alternative - wps office

Frequently Asked Questions

Why are my hyperlinks not clickable in the exported PDF?

This usually happens if 'IncludeDocProperties' is set to False in your VBA script, or if you attempt to use a virtual PDF printer (like Microsoft Print to PDF) instead of the ExportAsFixedFormat method. Ensure you use the specific VBA method described to retain hyperlink functionality.

How can I export the entire workbook to PDF instead of a single worksheet?

To export the whole workbook, change the object from the specific worksheet to the workbook itself in your VBA code. Replace 'ws.ExportAsFixedFormat' with 'ThisWorkbook.ExportAsFixedFormat' using the same parameters.

Can I specify a different output folder for the generated PDF?

Yes, you can modify the 'Filename' parameter in the script. Instead of using 'ThisWorkbook.Path', you can hardcode a specific directory path, such as 'Filename:="C:\Users\YourName\Documents\YourFileName.pdf"'.