How do I create a macro PDF?

While working in Microsoft Excel, you may face the problem of saving active worksheet as PDF file. In this article, you can learn how to save active worksheet as PDF file with VBA code through a Command Button. And if you also want to save a range or each worksheet in active workbook as individual PDF file, this article can also help you.

Use Command Button to save active worksheet as PDF file with VBA code
Easily save active or each worksheet as individual PDF file with Kutools for Excel


Use Command Button to save active worksheet as PDF file with VBA code

You can run the following VBA code to save an active worksheet as PDF file by clicking on a Command Button. Please do as follows.

1. Firstly, you need to create a folder named PDF for saving your new converted PDF file. Here I create this folder in my local disc (C:).

2. Please insert a Command Button by clicking Developer > Insert > Command Button (ActiveX Control). See screenshot:

How do I create a macro PDF?

2. Then draw a Command Button in to the worksheet you need to add new rows, right click the Command Button and click Properties from the right-clicking menu.

How do I create a macro PDF?

3. In the Properties dialog box, enter the displayed text of the Command Button into the Caption box under the Categorized tab, and then close the dialog box.

How do I create a macro PDF?

You can see the displayed text of the Command Button is changed as below screenshot shown.

How do I create a macro PDF?

4. Right click the Command Button again, and then click View Code from the right-clicking menu.

How do I create a macro PDF?

5. In the opening Microsoft Visual Basic for Applications window, please replace the original code in the Code window with the following VBA code.

VBA code: Command Button to save active worksheet as PDF

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:="C:\PDF\Export.pdf", _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub

Note: In the code, CommandButton1 is the Command Button name you will use to save active sheet as PDF file. "C:\PDF\Export.pdf" is the path and name of your saving PDF file.

6. Press the Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window. Then turn off the Design Mode under the Developer tab.

Now, click on the Command Button, the active worksheet will be saved as a PDF file named Export and located in the specified location.


Save each worksheet as individual PDF file of active workbook with Kutools for Excel

Here recommend the Split Workbook utility of Kutools for Excel to easily save active worksheet as a PDF file. Besides, you can also save each worksheet in current workbook as individual PDF file with this utility.

Before applying Kutools for Excel, please download and install it firstly.

1. In the workbook you need to save each worksheet as individual PDF file, then click Kutools Plus > Workbook > Split Workbook. See screenshot:

How do I create a macro PDF?

2. In the Split Workbook dialog box, please configure as follows:

2.1) Only check the active sheet name in the Worksheet name box;

2.2) Select PDF (*.pdf) option from the Save as type drop-down list;

2.3) Click the Split button, then a Select Folder dialog pops up, specify a folder to save the PDF file;

How do I create a macro PDF?

Then the selected worksheet is saved as PDF file immediately.

How do I create a macro PDF?

Notes:

1. You can check multiple worksheet names in the Worksheet name box to save them as individual pdf file at once;

2. Except for saving worksheet as pdf files, you can save worksheets as txt. or csv. file as you need.

  If you want to have a free trial ( 30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


Demo: Save selection or each worksheet as PDF with Kutools for Excel


Related articles:

  • How to insert a blank new row automatically by Command Button in Excel?
  • How to format cell to look like a 3D button in Excel?
  • How to hide or unhide a Command Button based on specified cell value in Excel?

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.

How do I create a macro PDF?


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

How do I create a macro PDF?

How do I create a PDF macro?

Create a text macro.
Choose Window > Text Macros..
If you want to create a text macro from existing text, select the text in the document..
Choose New Macro from the Text Macros panel menu, or click the New Macro button in the Text Macros panel..
Enter a macro code in the Macro Code text box..

How do I create a VBA PDF?

How To Save An Excel File As PDF Using VBA: The ExportAsFixedFormat Method.
The Workbook. ExportAsFixedFormat method, when saving an Excel workbook as PDF..
The Worksheet. ExportAsFixedFormat method, if you're saving a worksheet as PDF..
The Range. ExportAsFixedFormat method, when working with a Range object..
The Chart..

How do I create a macros?

Record a Macro.
Place the cursor where you want to start recording the macro..
Click the Record Macro button. ... .
Give the macro a name. ... .
Click the Keyboard button..
Press the keyboard shortcut keys that you want to use. ... .
Click Assign..
Click Close. ... .
Record the macro..