Update All Word Template AutoText Entries with VBA
Question details
Replace an outdated company name across more than 100 AutoText entries in a Word template without editing each entry individually.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A template contains many AutoText building blocks that need the same company-name change.
- Observed behavior
- The user wants the new company name to appear throughout the relevant AutoText entries while retaining the entries for future use.
Create a working copy of the template and test the macro on that copy in desktop Word. Enable the Developer tab if needed, and make sure the template is writable and the relevant AutoText entries are in the General category.
Replace the company name in General AutoText entries with VBA
Use this macro to select a template, update matching AutoText entries in the General category, and save the template.
The macro inserts each matching building block into a temporary document, replaces the text, and recreates the entry with its original name, description, and insertion option. Replacement is case-sensitive and applies to text Word Find can reach in the inserted document range.
Word Find treats certain characters, such as the caret, as special codes. Test names containing special characters on a copy first. Inspect entries with complex objects, fields, or unusual formatting after the update.
In desktop Word, open Developer > Visual Basic, then choose Insert > Module. If Developer is hidden, enable it in Word's ribbon customization settings.
Paste this code into the module: Sub UpdateTemplateAutoText() Dim picker As FileDialog Dim path As String, oldName As String, newName As String Dim host As Document, tempDoc As Document Dim tpl As Template, bb As BuildingBlock Dim entryName As String, categoryName As String, description As String Dim insertOption As WdDocPartInsertOptions Dim i As Long, updated As Long Dim changed As Boolean Set picker = Application.FileDialog(msoFileDialogFilePicker) With picker .Title = "Select a Word template" .AllowMultiSelect = False .Filters.Clear .Filters.Add "Word templates", "*.dot;*.dotx;*.dotm" If .Show <> -1 Then Exit Sub path = .SelectedItems(1) End With oldName = InputBox("Enter the old company name:") newName = InputBox("Enter the new company name:") If Len(oldName) = 0 Or Len(newName) = 0 Then Exit Sub On Error GoTo Failed Set host = Documents.Add(Template:=path, Visible:=False) Set tpl = host.AttachedTemplate For i = tpl.BuildingBlockEntries.Count To 1 Step -1 Set bb = tpl.BuildingBlockEntries(i) If bb.Type = wdTypeAutoText And bb.Category.Name = "General" Then Set tempDoc = Documents.Add(Visible:=False) bb.Insert Where:=tempDoc.Range(0, 0), RichText:=True With tempDoc.Range(0, tempDoc.Content.End - 1).Find .ClearFormatting .Replacement.ClearFormatting .Text = oldName .Replacement.Text = newName .Forward = True .Wrap = wdFindStop .MatchCase = True .MatchWholeWord = False .MatchWildcards = False changed = .Execute(Replace:=wdReplaceAll) End With If changed Then entryName = bb.Name categoryName = bb.Category.Name description = bb.Description insertOption = bb.InsertOptions bb.Delete tpl.BuildingBlockEntries.Add Name:=entryName, Type:=wdTypeAutoText, Category:=categoryName, Range:=tempDoc.Range(0, tempDoc.Content.End - 1), Description:=description, InsertOptions:=insertOption updated = updated + 1 End If tempDoc.Close SaveChanges:=wdDoNotSaveChanges Set tempDoc = Nothing End If Next i If updated > 0 Then tpl.Save host.Close SaveChanges:=wdDoNotSaveChanges MsgBox updated & " AutoText entries updated." Exit Sub Failed: MsgBox "The update stopped: " & Err.Description & vbCrLf & _ "The macro did not complete its save. Close Word without saving template changes and retry with a fresh copy." On Error Resume Next If Not tempDoc Is Nothing Then tempDoc.Close SaveChanges:=wdDoNotSaveChanges If Not host Is Nothing Then host.Close SaveChanges:=wdDoNotSaveChanges End Sub
Place the cursor in UpdateTemplateAutoText and press F5. Select the working-copy template, then enter the old and new company names when prompted.
Review the reported number of changed entries. Create a document from the updated template and insert several entries through Insert > Quick Parts > AutoText to verify their text and formatting.

Work with Word documents in WPS Writer
WPS Office is a free, lightweight Office alternative with a familiar interface and support for Microsoft Word formats, making it easy to move everyday document work. The Word AutoText template macro above must be run and verified in Microsoft Word.

Frequently Asked Questions
Does the replacement match the company name's capitalization?
Yes. The macro sets MatchCase to True, so enter the old company name with the exact capitalization used in the entries.
How can I update AutoText entries in another category?
In the VBA editor, change "General" in the category comparison to the exact category name, then run the macro again on a working copy.
Will the macro update every building block in the template?
No. It processes AutoText building blocks in the named category only. Other building block types and categories are excluded.
Does the macro apply a new style to the replaced name?
No. It replaces text and recreates the entry, but does not explicitly apply a style. Check the resulting formatting and modify the VBA separately if a specific style is required.
What should I do if the macro reports an error?
Close Word without saving the template changes, then retry with a fresh working copy. Confirm that the template is writable and test any names containing Word Find special characters.




