Convert Excel to PDF Using Macros (VBA) in Excel 365 – (Quick Ways)
Tags: convertexceltopdfusi, vbamacros
Published: 2020-10-01 07:06:18

---
title: Convert Excel to PDF Using Macros (VBA) in Excel 365 – (Quick Ways)
published: true
date: 2020-09-30 12:15:32 UTC
tags: ConvertExceltoPDFUsi,VBAMacros
canonical_url: https://geekexcel.com/convert-excel-to-pdf-using-macros-vba-in-excel-365-quick-ways/
---

## Convert Excel to PDF Using Macros:

In this post, we are going to explore how to **Convert Excel to PDF Using Macros** in **Excel Office 365** with examples. Let’s get started!! Get an official version of **MS Excel** from the following link: [https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)

## **Convert Excel to PDF:**

### **Excel to PDF Conversion Using Save As Option:**

To convert Excel to PDF using the “ **Save As”** option, do as follows.

- First, you need to **select a table** that you want to convert as PDF format.

![Select a table](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Select-a-table.png)<figcaption id="caption-attachment-14859">Select a table</figcaption>

- Go to the **File Tab, select** the **Save As** option, then **select** the **Browse** option from the window.

![File Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/File-Tab.png)<figcaption id="caption-attachment-14860">File Tab</figcaption>

![Select Browse option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Select-Browse-option.png)<figcaption id="caption-attachment-14861">Select Browse option</figcaption>

- It will open the **Save As dialog box** , where you need to **choose the location to save the PDF file**.

![Choose any location](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-any-location.png)<figcaption id="caption-attachment-14862">Choose any location</figcaption>

- In the **Save as type box** , **choose** the **PDF** option using the drop-down list.

![Choose PDF option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-PDF-option.png)<figcaption id="caption-attachment-14863">Choose PDF option</figcaption>

- Then, you need to **click** the **Options** button to customize the PDF file.

![Click the Options button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Click-the-Options-button.png)<figcaption id="caption-attachment-14866">Click the Options button</figcaption>

- Now, it will open the **Options Dialog**   **Box.**
- You need to **choose** the **Selection** Option under the **Publish What** section and **click** the **OK** button.

![Options Dialog box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Options-Dialog-box.png)<figcaption id="caption-attachment-14867">Options Dialog box</figcaption>

- If you want to publish the **entire sheet,** you have to cho **o** se the **Active Sheet(s)** option, and to publish the workbook, **select** the **Entire Workbook** option.
- Then, you need to **click** the **Save** button.

![Click the Save button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Click-the-Save-button.png)<figcaption id="caption-attachment-14868">Click the Save button</figcaption>

- Now, your Excel table will save in PDF format.

![Result](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Result-19.png)<figcaption id="caption-attachment-14869">Result</figcaption>

### **E**** xport Option:**

To export using quick access toolbar, follow the below steps.

- Go to the **File Tab**.

![File Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/File-Tab-1.png)<figcaption id="caption-attachment-14870">File Tab</figcaption>

- You need to **select** the **Export** option, **select** the **Create PDF/XPS Document** option, then **click** the **Create PDF/XPS Document button**.

![Choose create PDF/XPS Document option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-create-PDF-or-XPS-Document-option.png)<figcaption id="caption-attachment-14871">Choose Create PDF/XPS Document option</figcaption>

- It will open the **Publish as PDF or XPS dialog box** , where you need to **click** the **Publish** button to get the result.

![Click Publish option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Click-Publish-option.png)<figcaption id="caption-attachment-14872">Click Publish option</figcaption>

### **Export Using Quick Access ToolBar:**

You can add the Publish as PDF option to the quick access toolbar to access it quickly. To do this, follow the below instructions.

- You need to **right-click on the Quick Access Toolbar** (QAT) and **select** the **Customize Quick Access Toolbar** option.

![Choose Customize Quick Access Toolbar option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-Customize-Quick-Access-Toolbar-option.png)<figcaption id="caption-attachment-14873">Choose Customize Quick Access Toolbar option</figcaption>

- It will open the **Excel Options dialog box**.
- You have to **choose** the **Quick Access Toolbar option, ** then **choose** the **Publish**  **as PDF or XPS** option under the **Choose commands from** box.
- Then, **click** the **Add** button.

![Excel Options window](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Excel-Options-window.png)<figcaption id="caption-attachment-14874">Excel Options window</figcaption>

- Now, it will add **Publish as PDF or XPS** option under the **Customize Quick Access Toolbar section**.
- Hit the **OK** button.

![Click the OK button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Click-the-OK-button-1.png)<figcaption id="caption-attachment-14875">Click the OK button</figcaption>

- Now, you can see the **Publish as PDF or XPS** option in the Quick Access Toolbar as shown in the below image.

![Quick Access Toolbar](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Quick-Access-Toolbar.png)<figcaption id="caption-attachment-14876">Quick Access Toolbar</figcaption>

- You need to **click** on the **icon** and **select a file location** that you want to save it. Then, **click** the **Publish** button.

![Choose the file location](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-the-file-location.png)<figcaption id="caption-attachment-14877">Choose the file location</figcaption>

### **E-Mail PDF Using Quick Access ToolBar:**

Follow the below steps to email PDF using Quick Access Toolbar in Excel.

- You need to **right-click on the Quick Access Toolbar** (QAT) and **select** the **Customize Quick Access Toolbar** option.

![Choose Customize Quick Access Toolbar option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-Customize-Quick-Access-Toolbar-option.png)<figcaption id="caption-attachment-14873">Choose Customize Quick Access Toolbar option</figcaption>

- It will open the **Excel Options dialog box**.
- You have to **choose** the **Quick Access Toolbar option, ** then **choose** the **E-mail as PDF Attachment** option under the **Choose commands from** box.
- Then, **click** the **Add** button.

![Choose Email As PDF Attachment option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-Email-As-PDF-Attachment-option.png)<figcaption id="caption-attachment-14878">Choose Email As PDF Attachment option</figcaption>

- Now, it will add **E-mail as PDF Attachment** option under the **Customize Quick Access Toolbar section**.
- Hit the **OK** button.

![Hit the OK button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/1-110.png)<figcaption id="caption-attachment-14879">Hit the OK button</figcaption>

- Now, you can see the **E-mail**  **as PDF Attachment** option in the **Quick Access Toolbar** as shown in the below image.

![Result](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/2-90.png)<figcaption id="caption-attachment-14880">Result</figcaption>

### **Convert Excel to PDF Using VBA:**

You can also convert Excel to PDF using VBA code, do the below steps.

- First, you need to press ( **ALT + F11** ) shortcut keys to open the VBA editor as shown in the below screenshot.

![Open VBA Editor](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/3-49.png)<figcaption id="caption-attachment-14881">Open VBA Editor</figcaption>

- Then, **right-click the sheet name** and **select** the **Insert** option. Then, **choose** the **Module** option from the menu.

![Choose the Module option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/4-23.png)<figcaption id="caption-attachment-14882">Choose the Module option</figcaption>

- Kindly, **enter the below code**.

VBA code to convert Excel to PDF using Macros in Excel

**Sub PrintSelectionToPDF()**

‘Variable Declaration  
Dim rng As Range  
Dim strFilePath As String  
Dim strFile As String  
Dim file As Variant

‘Check if the range is selected or not  
If Selection.Count = 1 Then  
Set rng = Application.InputBox(“Please select a range”, “Get Range”, Type:=8)  
Else  
Set rng = Selection  
End If

‘You need to create the filename with the path  
strFile = “ExceltoPdf.pdf”  
strFile = ThisWorkbook.Path & “\” & strFile

‘It will open a save prompt for the username to select the location and filename  
file = Application.GetSaveAsFilename(InitialFileName:=strFile, FileFilter:=”PDF Files (\*.pdf), \*.pdf”, Title:=”Select location for the PDF file”)

‘Now, start the export process of the selected range  
If file <> “False” Then  
rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:=file, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False  
MsgBox “PDF file has been successfully created: ” & strFile  
Else  
MsgBox “Unable to create PDF file”, vbOKOnly, “No File Selected”  
End If

End Sub

![Enter the Source Code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/5-12.png)<figcaption id="caption-attachment-14883">Enter the Source Code</figcaption>

- You need to save the code using the **save button** or **click** ( **CTRL + S** ) keys and close it.
- In the **Save As** dialog box, **Choose** the **Excel Macro-Enables Workbook** option from the drop-down list and **click** the **Save** button.

![Choose the Excel Macro-Enables Workbook option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/6-10.png)<figcaption id="caption-attachment-14884">Choose the Excel Macro-Enables Workbook option</figcaption>

- On the **Developer Tab, choose** the **Macros option** in the **Code** section or **click** ( **ALT + F8** ) keys to open the **Macro dialog box**.
- Now, **choose** the **PrintSelectionToPDF** option located in **All Open Workbooks**. Then, **click** the **Run** option.

![Macro dialog box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/7-8.png)<figcaption id="caption-attachment-14885">Macro dialog box</figcaption>

- You have to **select the location** and **click** the **Save** button.

![Click the Save button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/8-5.png)<figcaption id="caption-attachment-14886">Click the Save button</figcaption>

- It will open the Microsoft Excel prompt box to tell you that the PDF has been created.

![Microsoft Excel Prompt Box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/9-4.png)<figcaption id="caption-attachment-14887">Microsoft Excel Prompt Box</figcaption>

- Finally, you can see that the Excel table is converted to PDF.

![Output](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/10-3.png)<figcaption id="caption-attachment-14888">Output</figcaption>

## **Conclusion:**

In the above article, you can clearly understand the ways to **Convert Excel to PDF Using Macros** in **Excel Office 365** with examples. Share your **feedback** in the comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!!

### Read Also:

- **[Add Date to Header Using Macros](https://geekexcel.com/how-to-add-date-in-header-using-macros-vba-in-excel-office-365/)**
- **[Add date to Footer using Macros](https://geekexcel.com/how-to-add-date-in-footer-using-macros-vba-in-excel-office-365/)**
- [**Unmerge All Cells Using Macros**](https://geekexcel.com/unmerge-all-cells-using-macros-vba-in-excel-office-365/)