Personal website of Gregory K. Maxey, Commander USN (Retired)
Do you have ad-blocking software enabled? While I respect your right to do so, your donations and the minimal advertisements on this site help to defray internet and other costs of providing this content. Please consider excluding this website from blocking or turning off the blocker while browsing this site.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.
If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!
This Microsoft Word Tips & Microsoft Word Help page provides a brief description of the use and construction of the AutoTextList field first introduced with Word 97. Yes, way back then!
With the introduction of content controls in Word 2007, some advanced Word users may feel that the AutoTextField has no place in the modern age.
I am not here to either promote or diminish its usefulness. My goal is simply to show you a VBA method to quickly create and employ an AutoTextField in your documents.
When introduced, the AutoTextList field provided the welcome advantage of a single item selectable dropdown list. The only alternative, way back then, was to use a protected formfield dropdown list with all baggage it brought along (e.g., suppressed spellchecking and other document tools).
The AutoTextList field leverages the fact (then and now) that Word, whether obviously or not, can organize AutoText entries (and building blocks) by the style applied to the text when the building block is created.
For example, all of the fruit and vegetable items shown in list below are individual building block entries defined and stored in my Normal template. They are isolated and filtered from the hundreds of other building blocks define in my Normal template because they were all created from text formatted with a unique style named "FVList." They are displayed in list format using an AutoTextList field.
As with all Word fields, the AutoTextList field can display the field result or underlying code:
Note: When you define an AutoTextList field with the user interface or code, a "literal text" attribute is used to set what the field displays (result) before making a selection. I don't know why this literal text attribute is not displayed in the field code.
A Google search will provide plenty of links to manual step by step procedures for defining and saving building blocks (autotext) entries and for creating an AutoTextList. Duplicating one of those wouldn't be very much fun!
The following is an automated VBA procedure that enables you to create an AutoTextList field (and save the field itself as a separate building block for reuse) with a few simple steps.
Sub DefineAutoTextList() 'Passes as arguments "Literal Text", "Sytle", _ '"Tip Text" and name of AutoTextList Building Block BuildATList "FVList", "Select", _ "Right-click to make your fruit/vegtable selection", "Fruit_Veggies" lbl_Exit: Exit Sub End Sub Sub BuildATList(strStyle As String, strLit As String, _ strTip As String, strListName As String) Dim oRng As Range, oATRng As Range Dim oPar As Paragraph Dim oFld As Field On Error Resume Next 'Creates style if not already present. ActiveDocument.Styles.Add (strStyle) On Error GoTo 0 Set oRng = Selection.Range 'Apply unique style to list items. oRng.Style = strStyle For Each oPar In oRng.Paragraphs 'Isolate and define building blocks. Set oATRng = oPar.Range oATRng.End = oATRng.End - 1 NormalTemplate.BuildingBlockEntries.Add oATRng.Text, _ wdTypeAutoText, "General", oATRng Next oPar 'Define and insert the field. Set oFld = ActiveDocument.Fields.Add(oRng, wdFieldAutoTextList, _ "" & Chr(34) + strLit & Chr(34) & _ " \s " & Chr(34) + strStyle & Chr(34) & " \t " & _ Chr(34) + strTip & Chr(34) & "", False) oFld.Code.Paragraphs(1).Style = "Normal" Set oRng = oFld.Code.Paragraphs(1).Range NormalTemplate.BuildingBlockEntries.Add strListName, _ wdTypeAutoText, "General", oRng 'If you want to get rig of the "Create AutoText ..." _ 'entry at the bottom of the list then unstet and run KillCat: 'KillCat If MsgBox("Changes have been made to your normal template." & vbCr + vbCr _ & "Do you want to save Normal templage now?", vbQuestion + vbYesNo, _ "SAVE CHANGES") = vbYes Then NormalTemplate.Save End If lbl_Exit: Exit Sub End Sub Sub KillCat() Dim lngIndex As Long Dim oCB As CommandBar Set oCB = ActiveDocument.CommandBars("Field AutoText") For lngIndex = oCB.Controls.Count To 1 Step -1 If oCB.Controls(lngIndex).Caption = "&Create AutoText..." Then oCB.Controls(lngIndex).Delete Exit For End If Next lbl_Exit: Set oCB = Nothing Exit Sub End Sub
Advanced users already know or won't be surprised to discover that the AutoTextList displayed in the document is actually a CommandBar. Yes, a CommandBar even in Word 2007 and higher. If you don't like the unsightly "Create AutoText ..." at the trail of your AutoTextList, you can delete it by including the call to KillCat in the code above.
See: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.
Note: This tips page, illustrations and examples were developed using Word 2010. It is wholly functional with Word 2003 trough 2016.
That's it! I hope you have found this tips page useful and informative.
Do you want to make a payment for consulting work or donate to help support this site?
PayPal is a safe, easy way to pay online.
Use the appropriate currency "Donate" button to make a payment or donation.