Results 1 to 7 of 7

Thread: AutoText Exists

  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoText Exists

    What's the best method for checking for the existence of an autotext entry?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoText Exists

    Iterate thru (enumerate) the collection testing for the autotext .name in the for loop.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoText Exists

    How about showing us a code sample for this?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Do you mind if I interrupt?

    Kevin, do you ever get the feeling you are talking to yourself?

    Use this code and modify it as many times as all of you want. Feel free if each of you want to post your answers.

    Dim Entry
    'Form types listing - Autofill the list with Autotexts in template
    For Each Entry In ActiveDocument.AttachedTemplate.AutoTextEntries
    Me.FormTypeLB.AddItem Entry.Name
    Next Entry
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Do you mind if I interrupt?

    Hey! I resemble that, and so do I! Thanks for helping us,
    Andrew. I think I'll post some code too. Me, too.

    Here's a function that tests to see if an autotext entry exists in a template. The template name and autotext piece name are parameters.

    <pre>Function AutoTextExists(aTemplate As Template, aPiece As String) As Boolean
    Dim aEntry As AutoTextEntry

    On Error GoTo BadName
    For Each aEntry In aTemplate.AutoTextEntries
    If UCase(aEntry.Name) = aPiece Then
    AutoTextExists = True
    Exit Function
    End If
    Next
    AutoTextExists = False
    Exit Function
    BadName:
    MsgBox "The template "+cstr(aTemplate)+ " or document text requested" + aPiece + " does not exist. ", vbCritical + vbOKOnly, "Autotext Retrieval Error"
    End Function</pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoText Exists

    No need loop through all AutoText entries. Try this instead:

    Function AutoTextExists(AutoTextName As String, _
    Optional InsertIfExists As Boolean) As Boolean
    Dim DOT As Template
    Dim ATX As AutoTextEntry
    ' Loop through all available templates

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoText Exists

    Hi Don,

    That's a good solution. A bit more elegant than mine. I especially like setting the autotext entry to an object and letting Word error if it does not exist. Thanks!
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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