This page updated 29 Feb 2010
Version note: Applies to TMG 8 & 9
This article describes how to record a macro in Word 2007, including step-by-step instructions for recording a macro I have designed to reformat Journal reports created in TMG. Readers can use these instructions to record their own macros, using, if they find them useful, the techniques I have used as a guide in creating your own sequence of steps.
Topics Included in this Article |
|
How to record a macro in Word 2007 | |
An overview of the edits done by Terry's Word macro | |
A step-by-step guide to recording Terry's Word macro |
Those who would prefer to download and install the macro I have created should see my article on Downloading Terry's Word Macro. Readers using a version of older than Word 2007 please see my article for Word97.
The following steps describe how to record a macro in Microsoft Word 2007; minor adjustments may be required for later versions. If you use an earlier version of Word see my article for recording macros in Word97.
Once you have perfected your sequence, start again with a fresh unedited copy of your file, and you are ready to record.
Click the Button button to open the Word Options screen.
Select the name of your macro in the left pane, and click the Add button to move it to the right pane.
Click the Keyboard button to open the Customize Keyboard screen.
Click in the "Press new shortcut key" field, then press the key combination you want to assign (usually Ctrl, Shift, or both with a letter key).
Click the Assign button, then Close to start recording.
Click OK, and recording starts. The cursor changes to show that recording is underway.
To test the macro, open a fresh unedited copy of the file and click the toolbar button you added in step 5 above, or use the keystroke you set in Step 6. If you did neither click the Macros button shown above, choose "View Macro," and in the Macros dialog box, select your macro, and click Run.
If you made an error in recording, start over with a fresh copy of your document, using the same name for the macro.
The macro I have created makes the following changes to TMG's Journal reports:
Change top and bottom margins, and spacing of footer from bottom of page.
Underline the "Generation xxxx" headings, and remove a blank line after each heading.
Remove blank lines TMG inserts immediately before and after the report title.
Reformat endnotes into two columns and adjust the spacing between notes.
The steps below are designed to make the formatting changes described above. The specific steps that you would record depend on exactly what you want to accomplish. The steps outlined below illustrate a number of useful techniques, and should be helpful as a guide in creating your own sequence of steps. You could of course add or delete steps, or modify the specific settings, to suit your preferences, or adapt the techniques to do entirely different tasks.
Before starting to record the macro, you need to open in Word a report of the type the macro will apply to. Then start macro recording as describe above and complete all the steps you want the macro to produce.
The steps in this section set the margins to values not available within TMG.
On the Page Layout ribbon, click the small arrow at the lower right of the Page Setup section to open the Page Setup dialog box.
On the Margins tab of that dialog box, make the following settings in the Margins section using the little up and down arrows: Top = 0.7, Bottom = 0.8, Left = 0.5, Right = 0.5.
At the bottom of that tab, set the "Apply to" drop-down to "Whole document."
On the Layout tab of that dialog box, under "Headers and footers" set Footer to 0.3
Click OK
The steps in this section add an underline to each of the "Generation xxx" section labels.
On the Home ribbon, in the Editing section, click the down arrow and select Replace to open the Find and Replace dialog box.
In that dialog box, click the More button (unless the Less button is present - in that case you are already in More mode).
Enter in the "Find what" field: Generation *> [this causes the Find function to select text starting with "Generation" and then all the remainder of the text on that line – the space between the word "Generation" and the asterisk is required].
Tick the "Use wildcards" box under Search Options.
Click in the "Replace with" field, but don't type anything, but delete anything that might be left over from a previous search
With the cursor still in the "Replace with" field, at the bottom of the dialog box, click Format and choose Font to open the Replace Font dialog box.
In the "Underline style" drop-down choose the single line, and click OK to return to the Find and Replace dialog box.
Click the "Replace All" button
When you get the confirmation box stating the number of replacements, click OK to close that box, then click the Close button to close the Find and Replace dialog box.
These steps remove a single blank line in several places, including after the main title and the generation labels.
On the Home ribbon, in the Editing section, click the down arrow and select Replace to open the Find and Replace dialog box.
In that dialog box, click the More button (unless the Less button is present - in that case you are already in More mode).
Enter in the "Find what" field: ^p^p^p [the code for three paragraph marks in a row]
Untick the "Use wildcards" box under Search Options if it is checked.
In the " Replace with" field, enter: ^p^p [the code for two paragraph marks in a row, thus removing one of the three found]
With the cursor still in the "Replace with" field, at the bottom of the dialog box, click Format and choose Font to open the Replace Font dialog box. Restore "Underline style" to (none), and remove any other formatting that may be specified. Click OK to close the Replace Font dialog box.
Click the "Replace All" button.
When you get the confirmation box stating the number of replacements, click OK to close that box, then click the Close button to close the Find and Replace dialog box.
This step removes the blank line above the report title.
Key Ctrl-Home (to get to start of document).
Press the Delete key twice.
I wanted a footer format not available with the options in TMG. Rather than creating the footer in TMG and editing it, I turn off footers in the Report Definition screen, and create it from scratch in the macro.
Key Ctrl-Home (to get to start of document)
First, we add a line above the footer (a "border") and set up centered and right tabs for the text that is to be in the footer.
On the Home ribbon, in the Paragraph section, click the small down arrow next to the borders button, and select Top Border
Again on the Home ribbon, in the Paragraph section, click the small arrow at the lower right to open the Paragraph dialog box.
Click the Tabs button at the lower left corner of the dialog box to open the Tabs dialog box.
Click the Clear All button to remove any existing tabs.
In the "Tab stop position" field, enter 3.75, select Center under Alignment, and click the Set button.
Next we enter the actual text of the footer. Start with the cursor in the footer area at the bottom of the dialog box.
Key your name in the Footer, tab once and key the word "Page" and a space.
Without moving the cursor, on the Insert ribbon, in the Text section, click the "Quick Parts" button, and select "Field."
In the Fields dialog box, choose "Numbering" in the Categories drop-down, then select Page. Click OK to close the Fields dialog box.
Back in the footer, key a space, the word "of" and another space.
In the Fields dialog box, choose "Document Automation" in the Categories drop-down, then select NumPages. Click OK to close the Fields dialog box.
Back in the footer again, Tab once to the right side, and again on the Insert ribbon, in the Text section, click "Quick Parts" button, and select Field.
In the Fields dialog box, choose "Date and Time" in the Categories drop-down, then select Date.
In the Date Formats field, enter: d MMM yyyy [or select one of the available formats if you prefer]
Click OK to close the Fields dialog box.
Finally, we set the font size for the footer text.
Key Ctrl-A to select all footnote text
On the Home ribbon, in the Fonts section, select 9 under Size.
First we edit the Endnote Separators to remove the separator lines, which do not work well in double column mode, and adjust the heights of the now-blank lines to better align the left and right columns on the first Endnotes page.
On the View ribbon, in the Document Views section, click the Draft button to change to "draft" view.
On the References ribbon, in the Footnotes section, click the Show Notes button to open the notes pane at the bottom of the screen.
Select Endnote Separator in the drop-down, and key Ctrl-A, then Delete to remove the existing separator.
Key F8, then the right arrow, to select the paragraph mark, then on the Home ribbon, in the Fonts section, type 1 into the font size field, and press enter [this sets the height of that separator to 1 point, part of the process to make the top of the left column of endnotes even with the top of the right column].
Select Endnote Continuation Separator in the drop-down, and key Ctrl-A, then Delete to remove that separator too.
Key F8, then the right arrow, to select the paragraph mark, then on the Home ribbon, in the Fonts section, select 12 into the font size drop-down [this sets the height of that separator to 12 points, again to make the left column of endnotes even with the right column].
On the View ribbon, in the Document Views section, click the Print Layout button to close the Endnotes pane and return to the normal view.
This is the end of the steps that remove the separator lines. Now we move to setting up the endnotes themselves, arranging them in two columns, and adjusting the spacing between notes.
Key Ctrl-End to place the cursor in the Endnotes section.
In the Page Layout ribbon, in the Page Setup section, click the Breaks button, and select Continuous under Section Breaks.
Also in the Page Layout ribbon, in the Page Setup section, click the Columns button, and select "More Columns" at the bottom of the list, to open the Columns dialog box [you can choose Two directly on the drop-down list if adding columns manually, but due to an apparent bug in Word, you must use the Columns dialog box in macros to avoid an error when the macro is used – thanks to Tom Momeyer for finding this solution].
In that dialog box, click the Two icon under Presets, then click OK to close the dialog box.
Key F8, then the right arrow, to select the paragraph mark, then on the Home ribbon, in the Fonts section, type 1 into the font size field, and press enter [this sets the height of that blank line to 1 point, the final step to making the left column of endnotes even with the right column].
Key Down, Home, F8, then Ctrl-End to select all the endnote text.
On the Home ribbon, in the Paragraph section, click the small arrow at the lower right to open the Paragraph dialog box.
On the "Indents and Spacing" tab, under Spacing, in the Before field, use the little up/down arrows to enter 0 pt, in the After field enter 3 pt (you have to type it in), and click OK to close the Paragraph dialog box.
That is the end of the macro recording. Stop and save the macro, then test it to be sure it works as intended.
ReigelRidge Home | Terry's Tips Home | Contact Terry |
Copyright 2000- by Terry Reigel