Is there an efficient way of looking up a name in the AutoCorrect.Entries for MS Word to check if it exists (before I add a new entry with that name; I have the code that adds the entry and it works but it REPLACES the entry if it exists)
Sub AutoCorrection()
'
' AutoCorrect Macro
'
'
Dim selected As Variant
Dim name As Variant
'selected text gets stored as the selected
selected = Selection
'Checking if selected text is less than 2 characters.
If Len(selected) < 2 Then
MsgBox "Select text for autocorrect", vbOKOnly, "Nothing Selected"
Exit Sub
End If
'Displaying the selected text and getting input for the name
name = InputBox(selected, "Name for this autocorrect?")
'*** In here, I want to check if this name exists in the entries before adding a new entry ***
AutoCorrect.Entries.AddRichText name:=name, Range:=Selection.Range
End Sub
The following should work.
You would call it from your procedure with the name you want to use. It will report False if the name is not in use and True if it is.
You could skip the msgBox in the Function. This is NOT going to be fast if you have many entries.
btw, "name" is a terrible name for your variable, IMO.