In this post, we are glad to demonstrate you the way to batch add or delete multiple AutoText entries in your Word.
For texts you use frequently, you can use add them to AutoText gallery. So next time you won’t need to manually type all these texts again. Instead, you can find the target text entry and click it. And you will have them inserted into the position where your cursor stays.
Now as our topic suggests, we want to show you the method to batch add or delete multiple AutoText entries as to save your valuable time.
Batch Add Multiple AutoText Entries
- Firstly, you need to create a table of 2 columns. Put AutoText entry name into the first column. And put the entry content into the second column. Here is the demonstration:
- Next open VBA editor pressing “Alt+ F11”.
- Then click “Normal” project.
- Next click “Insert” tab on the menu bar and select “Module”.
- Now double click on the new module to open it.
- Paste following codes:
Sub BatchAddAutoTextEntries() Dim objTable As Table Dim objEntry As Cell Dim objEntryRange As Range Dim objEntryNameRange As Range Dim nRowNumber As Integer Set objTable = ActiveDocument.Tables(1) nRowNumber = 1 For Each objEntry In objTable.Columns(2).Cells Set objEntryNameRange = objTable.Cell(nRowNumber, 1).Range objEntryNameRange.MoveEnd Unit:=wdCharacter, Count:=-1 Set objEntryRange = objEntry.Range objEntryRange.MoveEnd Unit:=wdCharacter, Count:=-1 objEntryRange.Select NormalTemplate.AutoTextEntries.Add Name:=objEntryNameRange.Text, _ Range:=Selection.Range nRowNumber = nRowNumber + 1 Next objEntry MsgBox "All entries in the table are added to the gallery." End Sub
- Finally, click “Run” or hit “F5”.
When it’s finished, you will receive a message box such as bellow:
You won’t be able to see the added entries in current and all documents opened already. To see the effect you need to open a new document. Then you can check the result by clicking “Quick Parts” under “Insert” tab. Next choose “AutoText” and you shall see all entries in the table are added to the gallery.
Batch Delete Multiple AutoText Entries
In the following contents we will show you the way to batch delete multiple AutoText entries.
- First of all, create a table of one column. And put each entry name in one cell.
- Then repeat from step 2 to 7 above. But remember to replace macro with this one:
Sub BatchDeleteAutoTextEntries() Dim objTable As Table Dim objEntry As Cell Dim objEntryNameRange As Range Dim objEntryRange As Range Dim nRowNumber As Integer Set objTable = ActiveDocument.Tables(1) nRowNumber = 1 For Each objEntry In objTable.Columns(1).Cells Set objEntryNameRange = objTable.Cell(nRowNumber, 1).Range objEntryNameRange.MoveEnd Unit:=wdCharacter, Count:=-1 On Error Resume Next NormalTemplate.AutoTextEntries.Item(objEntryNameRange.Text).Delete nRowNumber = nRowNumber + 1 Next objEntry MsgBox "All entries in the table are deleted from the gallery." End Sub
Similarly, it takes effect in new documents opened afterwards.
Stay Cool When Data Loss Occur
As the increase use of computers, data loss also swells every year. Data loss can leave your career on the line. It is such a frustrating experience that one will never want to encounter with again. Then here comes the importance of doc fix. You should always keep a repairing tool in advance.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including Excel recovery and pdf repair software products. For more information visit www.datanumen.com
1