Hack 17 Make Styles More Manageable with AliasesAssigning short nicknames to styles can really speed up your formatting time. To quickly apply a style to selected text, put your cursor in the Styles pull-down menu on the Formatting toolbar, type in the style name, and press Enter.
In fact, Word will even attempt to complete the style name as you type, as shown in Figure 3-12. This feature helps if you're applying, say, the Heading 1 style, but it's not much of a shortcut for any of the other heading styles. Figure 3-12. Word attempts to automatically complete the style's name as you typeYou can't rename any of Word's built-in styles, but if you create an alias to a style (such as "h6" for the Heading 6 style), you can type the alias instead of the style's "real" name into the Styles pull-down menu. To create an alias for a style, select Format Figure 3-13. To create an alias for a style, just put the alias after a comma at the end of the style's nameNow, to apply the Heading 6 style, just enter "h6" in the Styles pull-down menu and press Enter.
In addition to creating shortcut names for styles, aliases can provide alternate descriptions of a style. For example, if you set up your document to use the Heading 1 style for chapter titles, you might consider adding an alias so the style's called "Heading 1,Chapter." Strings of aliases after each style can look a bit strange in the Styles pull-down menu (see Figure 3-14). But if you use the aliases, you'll rarely see the menu anyway. Figure 3-14. A list of styles with multiple aliases3.5.1 Using Aliases in VBA
When you apply a style from a macro, you can use its "real" name, any of its aliases, or its full name, including all of its aliases. For example, if the Heading 6 style had an alias of "h6," as described above, any of the following would apply it to the paragraph referenced by the variable para: para.Style = "Heading 6" para.Style = "Heading 6,h6" para.Style = "h6" para.Style = "h" & CStr(6) Because Heading 6 is one of Word's built-in styles, the following also works: para.Style = wdStyleHeading6 You can quickly remove all aliases in a document with a simple macro if, for example, you added aliases to someone else's document while you edited it: Sub RemoveAllStyleAliases Dim sty As Style For Each sty In ActiveDocument.Styles sty.NameLocal = Split(sty.NameLocal, ",")(0) Next sty End Sub The Split function used in this manner just removes everything after, and including, the first comma in the style name. If the style doesn't have any aliases, it leaves the name as is. |