Results 1 to 3 of 3
  1. #1
    sgerber
    Guest

    Test for existence of AutoText entry?

    Does anyone know if VBA provides a way to test for the existence of an AutoText entry?

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Test for existence of AutoText entry?

    Steve,

    You can use code like the following (comment out the line that refers to AttachedTemplate or Normal.dot, as appropriate):

    <pre>Public Sub TestForAutoTextEntry()

    Dim strATName As String

    strATName = InputBox("Type the name of the autotext entry")
    If DoesATExist(strATName) Then
    MsgBox "The autotext entry '" & strATName & "' does exist"
    Else
    MsgBox "The autotext entry '" & strATName & "' doesn't exist"
    End If

    End Sub
    '===========================
    Public Function DoesATExist(strName As String) As Boolean
    Dim ATE As AutoTextEntry
    'For Each ATE In ActiveDocument.AttachedTemplate.AutoTextEntries
    For Each ATE In Templates("Normal.dot").AutoTextEntries
    If ATE.Name = strName Then
    DoesATExist = True
    Exit Function
    End If
    Next ATE
    End Function</pre>


  3. #3
    sgerber
    Guest

    Re: Test for existence of AutoText entry?

    Wow. Gary, thanks a million!

    I did make one minor change to the routine, because the search was apparently case-sensitive:

    Public Sub TestForAutoTextEntry()

    Dim strATName As String


    strATName = UCase(InputBox("Type the name of the autotext entry"))

    If DoesATExist(strATName) Then
    Msgbox "The autotext entry '" & strATName & "' does exist"
    Else
    Msgbox "The autotext entry '" & strATName & "' doesn't exist"
    End If


    End Sub
    '===========================
    Public Function DoesATExist(strName As String) As Boolean
    Dim ATE As AutoTextEntry
    For Each ATE In ActiveDocument.AttachedTemplate.AutoTextEntries
    'For Each ATE In Templates("Normal.dot").AutoTextEntries
    If UCase(ATE.Name) = UCase(strName) Then
    DoesATExist = True
    Exit Function
    End If
    Next ATE
    End Function

Posting Permissions

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