Thursday, September 4, 2008

Macro-Enabled Template: Step 2 - Preparing The Form

This is step two in the series showing you how to create macro-enabled templates (METs). Click here for step one, preparing the document. For the finished product see the freebie file in this previous post.

Open up the document that you prepared in step one.  At this point we need to open up the Microsoft Visual Basic editor.  The easiest way to do this is by pressing ALT+F11 while having the template open in Word.  In the Project Pane on the left hand side find the name of your document, mine is template.pleading.  Right click on the name of your document, drag down to insert, then select UserForm.


If the blank form does not pop up expand the form folder and double click UserForm1 to display the blank form.

Now take a look at the Toolbox (if it isn't displayed click View>Toolbox).  There are several tools here that we will not need to use.  For now we're only going to focus on two, and later a third.

First Select the "Label" tool () and we'll begin creating our input boxes.  You can use whatever order is the most natural and user friendly to you for the input boxes. I prefer to place the boxes in roughly the order they appear in the document and also try to keep information that will be standardized in several other documents (County, Circuit, etc...) near the top as well. Click, with the label tool selected, in the upper left hand corner.  Now with the label created, look to the Properties pane on the left hand side (if it's not present hit F4).  The only two values we're going to be concerned about are "Name" and "Caption".  Change both to the appropriate label title (No spaces allowed in the "Name" field).

Now select the "TextBox" tool (). Click just to the right of the label and edit the "Name" field in the Properties pane to something appropriate (ex. CountyName, PFirstName, etc...).

Continue these two steps until you've created and labeled a Text Box for each bookmark you created earlier. Note however, that if you're using the same value for multiple bookmarks you only need to create one text box.  This is the whole point of using these METs, type information one time and it's replicated throughout the document as appropriate.

The final step in preparing the form is to insert the Command Buttons.  Click the command buttons icon () and place three buttons at the bottom of the form.  Edit the "Name" and the "Caption" to create a Submit/OK button, a Reset/Clear button and a Cancel button.

This concludes the preparation of the form.  The next step is to Code the Form, and as many of you may guess, it's the trickiest part of creating the METs.

2 comments:

  1. Brilliant post. Can't wait for Steps 3 & 4.

    Keep up good work.

    Thanks

    ReplyDelete
  2. Don't get lost on the mundane-ness of the example. A caption may be easy to reproduce, but imagine the power of automagically filling an entire purchase placement memorandum/articles of incorporation/ form interrogatories/ etc.

    ReplyDelete