Auto Correct Object Example

This example uses the AutoCorrect object to find the replacement to use for a given word:

Sub TestAutoCorrect()

MsgBox "'(c)' is replaced by " & UseAutoCorrect("(c)") End Sub

Function UseAutoCorrect(ByVal sWord As String) As String

Dim i As Integer

Dim vaRepList As Variant

Dim sReturn As String

'Default to returning the word we were given sReturn = sWord 'Get the replacement list into an array vaRepList = Application.AutoCorrect.ReplacementList 'Go through the replacement list

For i = LBound(vaRepList) To UBound(vaRepList) 'If there is a match, return the replacement text, else exit loop. If vaRepList(i, 1) = sWord Then sReturn = vaRepList(i, 2) Exit For End If


'Return the word, or its replacement if it has one UseAutoCorrect = sReturn End Function

0 0

Post a comment