Browse » Home
Saturday, November 26, 2011
How to Align Lines in a Word 2007 Macro
Record and Run
1. Open a Word 2007 document. In this method, lines must already exist in the document.
2. Go to “Tools” and select “Macro.”
3. Choose “Record New Macro.”
4. Select a macro name, assignment and where the macro will be stored. To run the macro from your keyboard or a toolbar, choose one of the assignment options. Otherwise, you must run the macro from the Macro window.If the macro is only for use in the current document, select the document name from the drop-down list. If the macro is for multiple documents, choose “All Documents.”
5. Align lines in your Word 2007 document. Select each line you wish to align and use the Formatting toolbar to align the lines.
6. Press the “Stop” button on the Macro toolbar when finished.
7. Run your macro when needed. You have three options.Toolbar button: If you assigned the macro to a toolbar button, press the appropriate button to run the macro.Keyboard: Press the correct key combination on the keyboard to run the macro if you assigned a key combination during creation.Macro window: Go to “Tools,” select “Macro” and choose “Macros.” Select your macro from the list and choose “Run.”
VBA Code
8. Open an existing Word 2007 document.
9. Go to “Tools,” select “Macro” and choose “Visual Basic Editor.”
10. Double click your document’s name in the “Project” window to open the code editor.
11. Type the following, without quotes, to create an alignment macro:
Sub MacroName()
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End SubReplace “MacroName” with the name of your macro. To align the line to the right replace “Left” with “Right.” To align center, replace “Left” with “Center.” To justify a line or paragraph, replace “Left” with “Justify.”This code assumes you’re starting with the first line of your document.
12. Align multiple lines by using the following code:Selection.MoveDown Unit:=wdLine, Count:=2Use MoveUp to move up in your document. Use MoveDown to move down in your document. The count is how many lines to move up or down in your document. For instance, if you want to move from the first line in your document to the fifth line in your document, use the following code: “Selection.MoveDown Unit:=wdLine, Count:=5.
13. Go to “File” and select “Save” to save your macro. Exit the VBA editor.
14. Go to “Tools,” select “Macro,” choose “Macros” and select your macro name to run it or assign it to a keyboard shortcut or toolbar button.