Simple Word macro/button to print out a form


April 1, 2008 – 12:45 pm by JP

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:
VBA:
  1. Private Sub CommandButton1_Click()
  2.  
  3. End Sub

  • Paste the following code in between those lines:
VBA:
  1. 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


Share and Enjoy:
  • StumbleUpon
  • Technorati
  • Digg
  • Google
  • del.icio.us
  • MisterWong

Print This Post Print This Post  |  Email This Post Email This Post  |  Permalink  |  Subscribe to this feed Subscribe now!

Filed Under: VBA, Word, automation
Tags: , ,

This post has 108 views since April 1, 2008 – 12:45 pm.

Post a Comment

To post VBA code in your comment, use [VBA] tags, like this: [VBA]Code goes here[/VBA].





Subscribe without commenting

Keep Reading:

Browse Posts:


« New webstore || Quickly Clear Conditional Formatting »