Simple Word macro/button to print out a form

Happy April Fool's Day!

Here is a simple macro in MS Word that you can use to print out a document to the default printer.

  • Go to View>Toolbars>Control Toolbox to display the Control Toolbox.
  • Click the "Command Button" icon to insert a command button in your document. You can drag it anywhere you like and resize as needed.
  • Double click the button to view the code window. You should be taken right inside an auto-created Click event that looks like this:
Private Sub CommandButton1_Click()

End Sub
  • Paste the following code in between those lines:
ActiveDocument.PrintOut
  • Press F4 to view the Properties window for the command button and change the "Caption" property to something like "Print" or something else useful.
  • Press Alt-Q to close the VB Editor and return to MS Word.
  • On the Control Toolbox, click "Exit Design Mode". You can close the toolbar if you wish.

Test it out by pressing the button! It will send your document to the default printer. Keep in mind the button is displayed on the document so it will be printed as well.

Enjoy,
JP

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »


Related Articles:


Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 4 Comment(s) on Simple Word macro/button to print out a form:

  1. Sophia Rous writes:

    Hi Jp,

    I have added an email button to a form and I am now trying to get it to give me the option to print a copy for my records…any help would be appreciated.

    The code I am using for emailing the form is below:

    Private Sub CommandButton1_Click()
    ActiveDocument.HasRoutingSlip = True
    With ActiveDocument.RoutingSlip
    .Subject = "Incident Hazard Report"
    .AddRecipient "my email address"
    .AddRecipient "someone else's email address"
    .Delivery = wdAllAtOnce
    End With
    ActiveDocument.Route
    ActiveDocument.HasRoutingSlip = False
    End Sub

    Thanks and kind regards

    Sophia

    • If you want to prompt the user first, try this:

      If MsgBox("Print this?", vbYesNo) = vbYes Then
        ActiveDocument.PrintOut
      End If

      PS- I edited your code to remove the email addresses.

  2. Sophia Rous writes:

    Cheers JP for responding. I have tried to add this to the code but to no avail and I am no computer guru.

    I detail the code below for some more help please.

    Private Sub CommandButton1_Click()
    ActiveDocument.HasRoutingSlip = True
    With ActiveDocument.RoutingSlip
    .Subject = "Incident Hazard Report"
    .AddRecipient "my email address"
    .AddRecipient "another email address"
    .AddRecipient "another email address"
    .AddRecipient "another email address"
    .Delivery = wdAllAtOnce
    End With
    ActiveDocument.Route
    ActiveDocument.HasRoutingSlip = False
    End Sub
    If MsgBox("Print this?", vbYesNo) = vbYes Then
      ActiveDocument.PrintOut
    End If
    • I removed the email addresses from your code, spammers love that sort of thing.

      The code should go before the "End Sub" portion of your code. Like this:

      Private Sub CommandButton1_Click()
      ActiveDocument.HasRoutingSlip = True
      With ActiveDocument.RoutingSlip
      .Subject = "Incident Hazard Report"
      .AddRecipient "my email address"
      .AddRecipient "another email address"
      .AddRecipient "another email address"
      .AddRecipient "another email address"
      .Delivery = wdAllAtOnce
      End With
      ActiveDocument.Route
      ActiveDocument.HasRoutingSlip = False
      
      If MsgBox("Print this?", vbYesNo) = vbYes Then
        ActiveDocument.PrintOut
      End If
      End Sub
This article is closed to any future comments.
Excel School