Maintain Autotext Entries From An External Table

Home Up Search This Site What's New? Audio On CDR Favourites Downloadable files Photo Gallery 2002 Photo Gallery 2003 Photo Gallery 2004/5 Photo Gallery 2006/7 Photo Gallery 2008 UK Photo Gallery Ireland Photo Gallery Cats Photo Gallery 

 

 

Google
 

 

 

There is no charge for using any of the material (for personal use) on this web site, but if you wish to make a contribution to the ever growing running costs, any donation would be much appreciated. Click the adjacent button to access PayPal

Create autotext entries from a Word table

 

Word 2007 has changed how autotext works, and the removal of auto-complete from that version renders it less convenient, but there are still plenty of people using earlier versions, who wish to maintain lists of autotext entries. It is at those users that this page is aimed.

Word provides the mechanism to edit entries individually, but it is possible to maintain a list of autotext entries in a Word table and apply them to a Word template.

The list of entries is stored in a document containing a two column Word table, which is saved here with the name

"D:\My Documents\Test\AutotextTable.doc". The name and path of the document are unimportant as long as they are entered into the macros in place of this name and path.

 

The first column contains the autotext names. The second column contains the texts associated with those names.

Autotexts are filed in Word according to the style that was attached to the text when the entry was created. If the entry contains the paragraph mark that terminates the entry (circled in red), it will be stored with the formatting that is associated with the applied style otherwise it is merely stored under the style name and when inserted adopts the formatting of the paragraph the text is inserted into. Manual formatting is retained in either instance.

 

The following macro loads the table document, reads each entry from the table, and enters it into the Normal template overwriting any existing autotext entry of the same name. If you don't know how to use macro listings, see http://www.gmayor.com/installing_macro.htm

 

Sub AutoTextFromTableAdd()
Dim aTextDoc As Document
Dim cTable As Table
Dim rName As Range, rText As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\AutotextTable.doc"
Set aTextDoc = Documents.Open(sFname)
Set cTable = aTextDoc.Tables(1)

For i = 1 To cTable.Rows.Count
Set rName = cTable.Cell(i, 1).Range
rName.End = rName.End - 1
Set rText = cTable.Cell(i, 2).Range
rText.End = rText.End - 1

NormalTemplate.AutoTextEntries.Add name:=rName, _
Range:=rText
Next i
aTextDoc.Close wdDoNotSaveChanges
End Sub

 

The following macro deletes from the Normal template the list of autotext entries stored in the table.

Note:

If you plan to reduce the number of autotext entries by deleting some unwanted items from the table, run the following macro BEFORE deleting the entries from the table, or they will remain in the Normal template after the changes have been made. The macro only deletes entries named in the table!

 

Sub AutoTextFromTableDelete()
Dim aTextDoc As Document
Dim cTable As Table
Dim rName As Range, rText As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\AutotextTable.doc"
Set aTextDoc = Documents.Open(sFname)
Set cTable = aTextDoc.Tables(1)

On Error Resume Next
For i = 1 To cTable.Rows.Count
Set rName = cTable.Cell(i, 1).Range
rName.End = rName.End - 1
NormalTemplate.AutoTextEntries(rName).Delete
Next i
aTextDoc.Close wdDoNotSaveChanges
End Sub

 

In the example above the first entry from the table is formatted in Heading 1 style and thus appears in the Heading 1 listing. When inserted, because the paragraph mark is included, the entry is formatted with the Heading 1 style thus:

 

In the case of the entry "text2" this does not include the paragraph mark so is formatted with the style of the paragraph into which it is inserted, but retains the manual formatting thus: