bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Editing > AutoText > Macro-Inserted AutoText Doesn't Set Style

Macro-Inserted AutoText Doesn't Set Style

Summary: Inserting AutoText from a macro can give unwanted results, particularly when it comes to any style that may be stored with the AutoText entry. The solution is to make sure your macro uses the RichText parameter, as described in this tip. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)

Glenn is inserting an AutoText entry into his document using a macro. When he inserts the entry manually (not from the macro), Word sets the style properly for the entry using the style (Heading 3) stored with the AutoText entry. But when he uses the macro to insert the AutoText entry, the inserted entry shifts to another style (Body Text).

The first thing to check is that there is really a style stored with the AutoText entry. In this case, the style is stored with the entry if the paragraph mark at the end of the text was selected when the entry was defined. (It probably is this way in Glenn's case since the style is set properly when manually inserting the AutoText, but it is still a good thing to check.)

Once you are sure that the style has been saved with the document, you need to take a look at your macro and how the AutoText entry is being inserted. If you have an AutoText entry named "MyText," the normal way to insert it is to use a macro line such as the following:

NormalTemplate.AutoTextEntries("MyText").Insert Where:=Selection.Range

If you want the formatting of the AutoText entry to be used, however, you need to make sure that the optional RichText parameter is used:

NormalTemplate.AutoTextEntries("MyText").Insert _
  Where:=Selection.Range, RichText:=True

Your AutoText should now be inserted exactly as you want it to be inserted.

Tip #314 applies to Microsoft Word versions: 97 | 2000 | 2002 | 2003


More Power! Expand your skills and make Word really sing! It's all possible with macros. The best resource anywhere for macros is WordTips: The Macros. Check it out today!

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Vital News Home

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)