Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoCorrect Entry (Word 2000)

    I would like to add some entry in the autocorrect, but first I want to make sure if they are not already existed. Here is a partial of the code I am going to work with. I want to know if I am in the right track.

    Dim Name1 As String
    Dim Name2 As String
    Dim Name3 As String
    Dim Name4 As String

    Name1 = "test1"
    Name2 = "test2"
    Name3 = "test3"
    Name4 = "test4"

    Dim MyEntry(1 To 10) As String
    Dim MyValue(1 To 10) As String

    Dim anEntry As AutoCorrectEntry

    For Each anEntry In AutoCorrect.Entries
    If (anEntry.Name <> Name1) & (anEntry.Name <> Name2) _
    & (anEntry.Name <> Name3) & (anEntry.Name <> Name4) Then
    For i = 1 To 10
    AutoCorrect.Entries.Add Name:=MyEntry(i), Value:=MyValue(i)
    Next i
    End If
    Next

    I am not too sure if the for each statement is the one to use. I only want the value inside the for loop to enter to the autoentry once. I don't want the loop to repeat after 10 time. All that I need, if the entries are not listed in the autocorrect entry, just add them.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AutoCorrect Entry (Word 2000)

    Unless you are clearing it out, AutoText.Entries is a very large collection. To iterate over the entire collection trying to rule out the presence of four different entries is a time-consuming task. I suggest that you test for the existence of each entry "directly" by trying to retrieve its value and checking the error code returned, if any. Here's an example of what I mean:

    <pre>Dim MyEntry(1 To 4) As String, MyValue(1 To 4) As String
    Dim strTest As String, intCounter As Integer
    MyEntry(1) = "Code1" 'etc.
    MyValue(1) = "Text1" 'etc.
    On Error Resume Next
    For intCounter = 1 To UBound(MyEntry)
    strTest = AutoCorrect.Entries(MyEntry(intCounter)).Value
    If Err.Number > 0 Then
    If Err.Number = 5491 Then
    'This AC entry does not exist; add it
    AutoCorrect.Entries.Add Name:=MyEntry(intCounter), _
    Value:=MyValue(intCounter)
    Else
    MsgBox "Error accessing value of AutoText entry:" & vbCrLf & vbCrLf & _
    Err.Number & " = " & Err.Description
    Exit Sub
    End If
    Err.Clear
    End If
    Next
    On Error GoTo 0</pre>

    Disclaimer: I didn't actually run this myself.

    Does this approach work for your application?

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoCorrect Entry (Word 2000)

    I like your idea, I will try to test it and let you know. Basically, I am working in an installation to add some autocorrect entry to another language. What I want to doulble check if these entries have not been entered in the autocorrect entry. Do do that, I will try to check 6 instances. If they don't exist, I will add them. I will add this macro in the autonew and autoopen so it can only be executed at once.

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •