WD2000: How to Use AutoCorrect on an Existing Document

This article was previously published under Q210869
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
The AutoCorrect feature works dynamically when you type a space after a word that appears in the AutoCorrect list. This feature operates while you create the document, but Word does not automatically scan a previously-created document and make AutoCorrect changes.

This article provides a sample macro that compares each word in a Word document to words in the AutoCorrect list and then replaces the matched words with the text string specified in the AutoCorrect list.

NOTE: If you are working on a very long document, this macro may take a long time to run. To stop the macro before it is finished, press CTRL+BREAK and then click End when you receive the following Microsoft Visual Basic message:
Code execution has been interrupted
When you save the document, Word saves all changes you made up until you pressed CTRL+BREAK.
MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For more information about how to use the sample code in this article, clickthe article number below to view the article in the Microsoft Knowledge Base:
212536 OFF2000: How to Run Sample Code from Knowledge Base Articles
Place the following code in the Declarations section of your code page:
Option ExplicitDim anEntryDim myMatchDim myConfirm				
Create the following macro to search your active document, identify words that appear in both the document and the AutoCorrect list, prompt you to replace the word, and then insert the corresponding AutoCorrect text.
Sub ReplaceAutoCorrectText()Application.ScreenUpdating = TrueSelection.HomeKey unit:=wdStory, Extend:=wdMove   With ActiveDocument.Content.Find   .ClearFormatting      Do While .Execute(FindText:=" ", Forward:=True, Format:=True) = True         Selection.MoveRight unit:=wdWord, Count:=1, Extend:=wdExtend              For Each anEntry In AutoCorrect.Entries         If anEntry.Name = Selection Then            Selection.Words(1).Select            myMatch = True            myConfirm = MsgBox("Are you sure you want to replace " _               & Chr$(34) & anEntry.Name & Chr$(34) & " with " & Chr$(34) _               & anEntry.Value & Chr$(34) & "?", vbYesNo)                  If myConfirm = vbYes Then                     Selection.TypeText (anEntry.Value)                     Exit For                  End If         End If      Next anEntry      Selection.MoveLeft unit:=wdCharacter, Count:=1, Extend:=wdExtend              For Each anEntry In AutoCorrect.Entries         If anEntry.Name = Selection Then            Selection.Words(1).Select            myMatch = True            myConfirm = MsgBox("Are you sure you want to replace " _               & Chr$(34) & anEntry.Name & Chr$(34) & " with " & Chr$(34) _               & anEntry.Value & Chr$(34) & "?", vbYesNo)                  If myConfirm = vbYes Then                     Selection.TypeText (anEntry.Value) & " "                     Exit For                  End If         End If      Next anEntry              Selection.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdMove          LoopEnd WithEnd Sub				
REFERENCES
For additional information about the AutoCorrect feature in Word, click the article numbers below to view the articles in the Microsoft Knowledge Base:
212377 WD2000: General Information About Auto Features
207748 WD2000: How to Move Word AutoCorrect Entries Between Computers
212518 WD2000: How to Print a List of AutoCorrect Entries
For additional information about programming resources for Microsoft Word 2000, click the article numbers below to view the articles in the Microsoft Knowledge Base:
212623 WD2000: Macro Programming Resources
226118 OFF2000: Programming Resources for Visual Basic for Applications
vba
Properties

Article ID: 210869 - Last Review: 02/21/2014 00:32:03 - Revision: 2.1

Microsoft Word 2000 Standard Edition

  • kbnosurvey kbarchive kbdtacode kbhowto kbinfo kbmacroexample KB210869
Feedback