Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Searching Autotext Collection (Word 2003)

    Hi folks, can someone tell me, is it possible to search (and replace) within the contents of a large autotext collection? It's all in one template.

    I'd assumed it was (although I didn't know how) since it is possible to get a printout/document containing all the autotext texts, and if you can do that I assumed you can then work with that document, but now I'm not so sure ...!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching Autotext Collection (Word 2003)

    You can list autotext entries as follows:

    Sub ListAutoText()
    Dim tpl As Template
    Dim ate As AutoTextEntry
    Set tpl = NormalTemplate ' or another template
    For Each ate In tpl.AutoTextEntries
    Debug.Print ate.Name & ": " & ate.Value
    Next ate
    End Sub

    You can change the Value property. But you have to keep the following limitations in mind:
    - Value returns an unformatted string.
    - If the autotext entry is longer than 255 characters, Value returns only the first 255.
    - You can't set Value to a string longer than 255 characters.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Searching Autotext Collection (Word 2003)

    Ah, well, there you go, you see. The autotext entries are quite often well over 255 characters (several paragraphs, in fact) and it is important that they keep their formatting.

    Isn't there any other way to search the contents for specific words/phrases (and maybe do a find/replace on them)? Without those restrictions?! <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    {Edited for an afterthought] Another thing they wanted - when you type the first few characters of an autotext name Word puts up a little bubble with the first few words of the autotext entry - is there anyway to do something similar but optionally display the entire contents of the autotext? Or even the first 255 characters?
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching Autotext Collection (Word 2003)

    I think you'd have to do the following:
    - Loop through the AutoTextEntries collection.
    - Insert the autotext entry into a document.
    - Edit it (content and formatting, as necessary).
    - Delete the old autotext entry from the template using the Delete method of the AutoTextEntry object.
    - Create a new one from the edited version in the document, using the Add method of the AutoTextEntries collection of the template.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Searching Autotext Collection (Word 2003)

    Urk! Yes, you're probably right (you usually are). Sigh. Headache, here I come!

    What about the bubbles? (the bit I edited into the last post)?
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching Autotext Collection (Word 2003)

    Sorry, I was already composing my previous reply when you added the question about previewing the autotext entries. I don't see any way to do that.

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Searching Autotext Collection (Word 2003)

    Hans, I just found this in an old template:

    Sub AutoTexttList()
    Dim ATvar As AutoTextEntry
    Documents.add
    For Each ATvar In NormalTemplate.AutoTextEntries
    Selection.TypeText ATvar.Name & vbCr
    ATvar.Insert Where:=Selection.Range, RichText:=True
    Selection.TypeText vbCr & "-----------------------------------------------------------" & vbCr
    Next
    End Sub

    It looks like it does what your little loop did (in fact there's a strong possibility you wrote it for me years ago!), but does the 'richtext=true' bit mean it will bring it in formatted?

    I don't have anything here with lots of autotext entries to try it on, and I don't have access to the internet where I'm working right now so I can't try it now and I won't be able to access the Lounge tomorrow! My bosses have put in for me to have internet access but the wheels grind slowly, so who knows when (if) it'll come through!
    Beryl M


  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Searching Autotext Collection (Word 2003)

    Yes, RichText:=True specifies that the autotext entry will be inserted into the document with formatting intact.

    (I don't know where you found that code, you already mentioned it in 2002, in <post:=148,934>post 148,934</post:>).

Posting Permissions

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