How to Use the VBA Code to Create a Custom Print Button in Excel (5 Methods)

 

Method 1 – Print Dialog Box 

  • First, create a button by going to Developer >> Insert >> Button Box.

Use VBA Code to Make Print Button for Print Dialog Box in Excel

  • Drag the cursor to set the desired button size.

Use VBA Code to Make Print Button for Print Dialog Box in Excel

  • When the Assign Macro dialog box appears, give your macro a name and press New.

Use VBA Code to Make Print Button for Print Dialog Box in Excel

  • In the VBA window, type the following code:
Sub DialogBox()
Application.Dialogs(xlDialogPrint).Show
End Sub
  • Return to your sheet.

Use VBA Code to Make Print Button for Print Dialog Box in Excel

  • The DialogBox sub-procedure opens the Print dialog box when the button is clicked.
  • Customize the button name by right-clicking on it and selecting Edit Text.

Use VBA Code to Make Print Button for Print Dialog Box in Excel

  • Press the button to display the Print dialog box.

You can Print immediately or Save as a PDF for later use.


Method 2 – Print Active Sheet

  • Follow the first two steps from the previous method to create the button and assign a macro.
  • Name the macro and press New.

Use VBA Code to Make Print Button for Active Sheet

  • In the VBA window, write the following code:
Sub ActiveSheet()
ActiveSheet.PrintOut
End Sub
  • Return to your sheet.

Use VBA Code to Make Print Button for Active Sheet

  • The ActiveSheet sub-procedure prints the active sheet.
  • Click the button, and a dialog box named “Save Print Output As” will appear.

Use VBA Code to Make Print Button for Active Sheet

  • Provide a Name and Save the printed PDF.

Use VBA Code to Make Print Button for Active Sheet

To change the printer, follow these steps:

  • Click on File next to the Home tab.

  • Select the Print option.
  • Click on the drop-down menu to choose a printer.


Method 3 – Print Selected Sheets

Apply VBA Code to Create Print Button for Selected Sheets in Excel

  • In the VBA window, type:
Sub SelectedSheets()
ActiveWindow.SelectedSheets.PrintOut
End Sub
  • Return to your sheet.

Apply VBA Code to Create Print Button for Selected Sheets in Excel

  • The SelectedSheets sub-procedure prints the selected sheets.
  • Click the button to print the selected sheets.

Apply VBA Code to Create Print Button for Selected Sheets in Excel

  • Name the PDF and press Save.


Method 4 – Print Specific Sheet with Selected Range

Embed Excel VBA to Create Print Button for Specific Sheet with Selected Range

  • Assign the following VBA code to the button:
Sub SpecificSheetnRange()
With Sheets("SpecificSheet+Range")
   .PageSetup.PrintArea = "B2:D11"
   .PrintOut
 End With
End Sub
    • Click the button to Print the specified range on the specified sheet.

Embed Excel VBA to Create Print Button for Specific Sheet with Selected Range

Embed Excel VBA to Create Print Button for Specific Sheet with Selected Range

  • Name the PDF and press Save.


Method 5 – Print Active Sheet with Selected Range

Embed Excel VBA to Create Print Button for Active Sheet with Selected Range

    • A VBA window will open.
  • Write the VBA Code:
    • In the VBA window, write the following code:
Sub ActiveSheetnRange()
Range("B2:D11").PrintOut
End Sub
      • This code selects the range “B2:D11” and prints it.

Embed Excel VBA to Create Print Button for Active Sheet with Selected Range

  • Return to Your Sheet:
    • Go back to your Excel sheet.
  • Test the Button:
    • The ActiveSheetnRange sub-procedure is now associated with the button.
    • Click the button to print the specified range.
    • Provide a name and save the printed output.

    • Provide a name and save the printed output.

 

Read More: Excel VBA: Print Preview for Selected Range

 

Download Practice Workbook

You can download the practice workbook from here:

 

Related Articles

Get FREE Advanced Excel Exercises with Solutions!

Tags:

Md. Sourov Hossain Mithun
Md. Sourov Hossain Mithun

Md. Sourov Hossain Mithun, an Excel and VBA Content Developer at Softeko's ExcelDemy project, joined in October 2021. Holding a Naval Architecture & Marine Engineering degree from BUET, Mithun showcases expertise during his two-year tenure. With over 200 published articles on Excel topics, he earned a promotion to Team Leader, excelling in leading diverse teams. Mithun's passion extends to Advanced Excel, Excel VBA, Data Analysis, and Python programming, contributing significantly to the innovative and dynamic environment of ExcelDemy... Read Full Bio

3 Comments
  1. Excellent article. The next question is: I have an Excel sheet that utilizes the same layout and info, the only thing that needs changed is the information from one single drop down list which includes 13 locations (lines of information) that is stored on the separate “Data” sheet. How can I make one print button that would print each individual page with each location from the list or items in the drop down box? Please let me know if you can be of any assistance with this issue. Your help is greatly appreciated!

  2. Hello ANDY S, thanks for your feedback.
    I hope the following codes will be helpful for your problem.

    Sub Print_Button_for_DropDown()

    Sheets(“Data”).Range(“$B$4:$D$11”).AutoFilter Field:=2, Criteria1:=Range(“F4”).Value
    Sheets(“Data”).Select
    Sheets(“Data”).PrintOut

    End Sub

    Here, I have made a drop-down list in Cell F4 for the locations. Keep this cell in that sheet where the print button is located, that means the active sheet. You can change the reference and range in the codes according to your dataset.

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo