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

    Amending autotext collection (Word 2003 onwards)

    I'm still having fun with this ruddy autotext collection - which consists of approx 468 autotext entries, ranging from a single line of text to pages of formatted text and graphics in each! So, in order to do a global find and replace on this collection, I've already ascertained we can't do it in situ - Word replaces not only the word/phrase required but the entire autotext entry with the first 255 characters and removes all formatting. Not good.

    So - I'm looking at pulling each entry into a blank doc, doing a find and replace and resaving the entry back into the collection under its original name, presumably using a For-each loop.

    My question, however (at the moment!), is this - when I recorded retrieving an autotext entry from the template and pasting it into the document, Word recorded it as:

    Application.DisplayAutoCompleteTips = True
    NormalTemplate.AutoTextEntries("010400 Our credit ratings").Insert Where:= _
    Selection.Range, RichText:=True

    Now, the entry is NOT in the normal template, for a start, and secondly, if I replace 'NormalTemplate' with 'ActiveDocument.AttachedTemplate' I get a very basic set of half a dozen options, none of which is 'autotextentries' and the debug crashes if I do it anyway!

    How do I go about phrasing this, please?

    Many thanks!
    Beryl M


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

    Re: Amending autotext collection (Word 2003 onwards)

    IntelliSense fails when you type ActiveDocument.AttachedTemplate. but you should still be able to use

    ActiveDocument.AttachedTemplate.AutoTextEntries("0 10400 Our credit ratings").Insert Where:= _
    Selection.Range, RichText:=True

    If that fails, perhaps "010400 Our credit ratings" is *NOT* stored in the attached template.

  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: Amending autotext collection (Word 2003 onwards)

    But it won't let me - and it is! Honest!!

    See my screenshot!
    Attached Images Attached Images
    Beryl M


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

    Re: Amending autotext collection (Word 2003 onwards)

    Name is not a property of the AutoTextEntries collection as a whole, it is a property of individual entries. You should be able to use

    txtName = AtE.AutoTextEntries(1).Name

    to get the name of the first AutoTextEntry.

  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: Amending autotext collection (Word 2003 onwards)

    Thanks, Hans, but ... <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>
    Attached Images Attached Images
    Beryl M


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

    Re: Amending autotext collection (Word 2003 onwards)

    Well, I'm stumped. I hope that someone else can help you.

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Amending autotext collection (Word 2003 onwards)

    All I can suggest is to do some "manual" debugging. Use

    msgbox ActiveDocument.AttachedTemplate.Name

    to ascertain that the attached template is what you think it is.

    msgbox ActiveDocument.AttachedTemplate.AutoTextEntries.Co unt

    to see if the collection actually contains items.

    Alan

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Amending autotext collection (Word 2003 onwards)

    Hi Beryl
    I suggest running the following debugging code.
    <div style="width: 100%; background-color: #FFFFFF;"><code><font color=black><font color=blue>Option</font color=blue> <font color=blue>Explicit</font color=blue>
    <font color=blue>Public</font color=blue> <font color=blue>Sub</font color=blue> AT_test()
    <font color=blue>Dim</font color=blue> AtE <font color=blue>As</font color=blue> Template
    <font color=blue>Dim</font color=blue> txtName <font color=blue>As</font color=blue> <font color=blue>String</font color=blue>
    Dim i <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>
    <font color=blue>Set</font color=blue> AtE = ActiveDocument.AttachedTemplate
    Documents.Add DocumentType:=wdNewBlankDocument
    <font color=blue>With</font color=blue> AtE
    <font color=blue>For</font color=blue> i = 1 <font color=blue>To</font color=blue> .AutoTextEntries.Count
    Selection.TypeText _
    i & " " & .AutoTextEntries(i).Name
    Selection.TypeParagraph
    <font color=blue>Next</font color=blue> i
    <font color=blue>End</font color=blue> <font color=blue>With</font color=blue>
    <font color=blue>End</font color=blue> <font color=blue>Sub</font color=blue>
    </font color=black></code></div hiblock>
    Note the line "Dim AtE As Template"
    Regards
    Don

  9. #9
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Amending autotext collection (Word 2003 onwards)

    Beryl
    Are you running this code from VB or VBA?
    Regards
    Don

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

    Re: Amending autotext collection (Word 2003 onwards)

    Hi Don, thanks for this, it worked perfectly and produced a list of the autotext names - all 10 pages of it!

    That 'dim ate as template' line must have done the trick ... although I'll let you all know later when I've tried with my own code to see if it all goes together!

    Ta again!
    Beryl M


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

    Re: Amending autotext collection (Word 2003 onwards)

    In general, it is a good idea to declare all variables explicitly. See <post#=314,748>post 314,748</post#> for an explanation why that is important.
    You can require variables to be declared by inserting the line

    Option Explicit

    at the very top of the module. When you run the code or select Debug | Compile <project>, you will see an error message if you use variables without having declared them..

    You can have the line added automatically to new modules by ticking the check box "Require variable declaration" in Tools | Options in the Visual Basic Editor.

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

    Re: Amending autotext collection (Word 2003 onwards)

    Thanks, Hans, in fact I did have the line declared at the top of the module as 'public', but I had declared it as an autotextentry, which was probably what was causing the problem!

    <img src=/S/doh.gif border=0 alt=doh width=15 height=15>
    Beryl M


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

    Re: Amending autotext collection (Word 2003 onwards)

    Okay, I think I'm getting there - slowly! However, I've just discovered that you can't record the process of recording an autotext entry and saving it to a specified template (with a specific name, of course). At least, it didn't record it when I just tried! How do I find out the code to do this, please?
    Beryl M


  14. #14
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Amending autotext collection (Word 2003 onwards)

    Hi Beryl
    You might find it worthwhile to modify the TypeText statement to the following in order to identify leading and trailing spaces more readily.
    <pre> Selection.TypeText _
    i & " " & "<" & .AutoTextEntries(i).Name & ">"
    </pre>

    Regards
    Don

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

    Re: Amending autotext collection (Word 2003 onwards)

    The basic idea of adding an AutoTextEntry in VBA is

    ActiveDocument.AttachedTemplate.AutoTextEntries.Ad d "MyEntry", Selection.Range

    where ActiveDocument.AttachedTemplate can be replaced with another template object, and Selection.Range with another range object.

Page 1 of 3 123 LastLast

Posting Permissions

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