Microsoft Office Tutorials and References
In Depth Information
Inserting AutoText with No Formatting
Inserting AutoText with No Formatting
This procedure lets you insert an AutoText entry as plain text.
Example file:
Scenario: Prior to Word 97, there was a checkbox in the
AutoText dialog box that let the user choose whether an
AutoText entry should be inserted with its formatting or as
"plain text", so that it would adapt to the formatting of the
text at the insertion point. Although this functionality has
since been lost to the user interface, it is still available
through a macro.
This macro displays the built-in Insert | AutoText | AutoText
dialog box so that the user can select from the entire range
of AutoText entries. The dialog box does not execute,
however. Instead, the macro takes care of inserting the
AutoText, without any accompanying formatting.
View the Appendix to learn how to store this procedure
in a Standard module.
Option explicit¶
' * * * * *¶
Sub InsertAutoTextNoFormatting()¶
'Variable declaration¶
Dim tmpl As Word.Template¶
With Dialogs(wdDialogEditAutoText)¶
'Because "Display" is used, the macro¶
'takes care of the actual insertion.¶
'But only if the user chose the Insert button¶
If .Insert = -1 Then¶
'Loop through all loaded templates¶
For Each tmpl In Application.Templates¶
'Continue when error occurs¶
On Error Resume Next¶
tmpl.AutoTextEntries(.Name).Insert _¶
Where:=Selection.Range, RichText:=False¶
'If the AutoText name is not found in a¶
'template, an error is generated.¶
'Rather than displaying an error message,¶
'the error code is checked. If it's 0, then¶
'there was no error and the AutoText entry was¶
'inserted successfully. The macro can end¶
Search JabSto ::

Custom Search