XL7: Sample Macro to Edit AutoCorrect List

ID: Q142144

The information in this article applies to:

SUMMARY

The following examples contain Visual Basic for Applications macros that you can use to add items to and remove items from the Microsoft Excel AutoCorrect list.

With AutoCorrect, changes are made to existing text only when a cell is activated. In addition, the AutoCorrect feature is case sensitive. That is, if you type the original word in capital letters, the replacement will be entered in capital letters as well.

MORE INFORMATION

Microsoft provides examples of Visual Basic for applications procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

To add an item to the AutoCorrect list

1. In a new module sheet, enter the following code:

      Sub Add_Item()

         'The following macro code assigns "Msft" to replace any new
         'occurrence of the word "Microsoft".
         Application.AutoCorrect.AddReplacement "Microsoft", "msft"

      End Sub

2. Switch to a worksheet, and click Macro on the Tools menu. Run the
   Add_Item macro.

3. To verify that the item was added to the list, click AutoCorrect on the
   Tools menu and scroll to the bottom of the window.

4. To test the AutoCorrect entry, type "Microsoft" (without the quotation
   marks) in any cell on your worksheet, and press ENTER.

The word "Microsoft" in the cell should automatically be changed to "Msft."

To remove an item from the AutoCorrect list

1. In a module sheet, enter the following code:

      Sub Remove_Item()

         'The following macro code removes the replacement
         'item for "Microsoft".
         Application.AutoCorrect.DeleteReplacement "Microsoft"

      End Sub

2. Click Macro on the Tools menu, and run the Remove_Item macro.

3. To verify that the item was removed from the list, click AutoCorrect on

   the Tools menu, and scroll to the bottom of the window.

REFERENCES

For more information about creating macros that run automatically in Microsoft Excel version 7.0, click Answer Wizard on the Help menu and type:

   How do I edit the AutoCorrect list?

Additional query words: 7.00
Keywords          : kbcode kbprg kbhowto 
Version           : 7.0
Platform          : WINDOWS

Last Reviewed: September 3, 1997