Excel Macro To Save As PDF (5 Suitable Examples) - ExcelDemy
Có thể bạn quan tâm
Example 1 – Creating Excel Macro to Save Active Workbook as PDF
Steps:
- Select the sheets to save as pdf. You can select all the sheets by right-clicking on any sheet name and choosing Select All Sheets.
- Right-click on any sheet name and click on View Code. A module window will pop up.
- Enter the following macro. Modify the saveLocation part of the code with your own pdf file save location. Click on the Run button.
- To see the pdf, go to the file location that you put into the VBA code for saving exported pdf from Excel.
Read More: Excel VBA Macro to Save PDF in Specific Folder
Example 2 – Using Macro to Save Active Worksheet as PDF
Steps:
- Go to the sheet that you need to save as a pdf.
- Click on Developer >> Visual Basic >> Insert >> Module. A module window will pop up.
- Enter the VBA code below. Click on the Run You need to edit the saveLocation in the VBA code with your own file directory address where you want to save the exported pdf.
In this example, C:\Users\sohan\Desktop\Softeko\57-0040\PDF files is the file address to save the exported pdf files. And myPDF1 is the pdf file’s name.
Sub SavingActiveSheetsAsPDF() Dim saveLocation As String saveLocation = "C:\Users\sohan\Desktop\Softeko\57-0040\PDF files\myPDF1.pdf" ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:=saveLocation End Sub- You can see the saved location and name of exported pdf file from Excel.
Read More: Excel Macro to Save as PDF with Filename from Cell Value
Example 3 – Saving Excel Sheets in Separate PDF Files with Macro
3.1 Saving All Sheets as PDF
Steps:
- Open an active workbook. Right-click on a sheet name and click on View Code. A new module window will pop up.
- Copy the following VBA code and paste it into the module window. Click on the Run button.
- Each sheet is saved as its own pdf file. And the files will be saved in the same location where your Excel file is located.
3.2 Saving Selected Sheets as PDF
Steps:
- Select the sheets one after the other by pressing Right-click on any selected sheet name and click on View Code. A new module window will pop up.
- Copy the following VBA code and paste it into the module.
- The pdf files are at the same location as the Excel file.
Example 4 – Saving a Particular Selection from Excel Sheet as PDF
Steps:
- Select the section that you want to save as a pdf. Right-click on the sheet name and click on View Code. A new module window will pop up.
- Enter the code below. Click Run.
- The pdf will be in the location entered into the VBA code at saveLocation..
Read More: Excel VBA: Choose Location and Save as PDF
Example 5 – Saving a Specific Range in Excel as PDF
Steps:
- Go to the sheet containing the range you need to save as a pdf.
- Go to the module window to enter the following VBA code modifying with your own save location. Click on the Run You can open a new module window either a right-click on the sheet name and clicking on the View Code or go to Developer >> Visual Basic >> Insert >> Module.
- The pdf file will be in the location that you put in the code.
Download Practice Workbook
Save as PDF with Macros.xlsmRelated Articles
- Excel VBA: Create Invoice and Save PDF Format
- Excel Macro: Save as PDF with Date in Filename
Từ khóa » Visual Basic Excel Save As Pdf
-
Save Excel As PDF With VBA
-
Excel VBA Save As PDF: Step-By-Step Guide And 10 Code ...
-
Excel Macro To Save Sheets As PDF - Contextures
-
Excel VBA Save As (Print) To PDF
-
Save File As PDF In VBA (macro)? | MrExcel Message Board
-
VBA Save Sheet As PDF - YouTube
-
Save Excel File As PDF Using VBA (Entire Workbook Or ... - YouTube
-
Save Excel As PDF With Excel VBA
-
Convert Excel To PDF Using VBA - The Only Guide You Will Need
-
How To Use Command Button To Save Active Worksheet As PDF File In ...
-
Export Docx To Pdf With Vba - Excel - Stack Overflow
-
Excel VBA SaveAs "Read-only" PDF File - Stack Overflow
-
Workbook.ExportAsFixedFormat Method (Excel) - Microsoft Docs
-
Excel VBA Save As PDF: Step-By-Step Guide And 10 ... - Pinterest