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

    Specify which templates Autocorrect can use? (WinNT/Word97)

    Just a pretty basic question, I think - if you want to use an Autotext entry, you can click on Tools > AutoCorrect > Autotext and specify at the bottom whether it is to look in "all active templates" or just in one specific one. Can you specify this in code? eg activedocument.autotextentries.lookin = "all active templates", or something like that?

    With some work I've been doing recently I've been changing this to look at the specific template I want (because there's a similar entry in the normal template as well and I don't want to pick that one up), but if I forget to put it back to "all active templates" the program falls over next time it runs something that wants an autotext entry from the normal, which is pretty irritating, so I'd like to put a line like the above in my work so it makes sure it's always looking in the right place, wherever that might be.

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> in advance!
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Specify which templates Autocorrect can use? (WinNT/Word97)

    Just specify the template with the command, like this.

    <code>NormalTemplate.AutoTextEntries(txtAutotextNa me).Insert Where:=rngTarget, RichText:=True</code>
    or
    <code>ActiveDocument.AttachedTemplate.AutoTextEntr ies(txtAutotextName).Insert Where:=rngTarget, RichText:=True</code>
    or
    <code>tmplMyGlobalTemplate.AutoTextEntries(txtAuto textName).Insert Where:=rngTarget, RichText:=True</code>

    Simple experiment shows that this doesn't change the defaults in the dialog box.

    StuartR

  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: Specify which templates Autocorrect can use? (WinNT/Word97)

    Thanks, Stuart, but it's not the lines in *my* program that are the problem - it's the ones in the normal.dot, which were written by someone else many moons ago and which I can't alter without giving myself an awful lot of work and irritating everyone else in the building by chucking them off the system so I can then replace the normal.dots!

    Also, I found in my code that if you have a large autotext entry with a lot of formatting, using that line removes all the formating - although I didn't have the 'richtext::=true' bit on mine, which would probably fix that.

    I really do have to find the code to switch the autotext 'lookin' back to 'all active templates', somehow!

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


  4. #4
    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: Specify which templates Autocorrect can use? (

    <P ID="edit" class=small>(Edited by jscher2000 on 17-Sep-04 11:37. Problems!!!)</P>> I really do have to find the code to switch the autotext 'lookin' back to 'all active templates', somehow!

    Are the names of the two AutoText entries identical? For example, the AttachedTemplate contains an entry called "Seeyalater" and so does Normal.dot or a global template? I'm curious which one Word inserts when you use your method. Does it follow the default rule of using the one closest to the document, that is, the one in the attached template?

    I tested interactively with two identically named entries, one in Normal.dot and one in a global template. If the Insert>Autotext>AutoText... dialog had the name of the global template in the Lookin dropdown, the one in the global template got inserted. However, if the default value of All Active Templates was selected, the one from Normal.dot got inserted. Seems to follow from the default rule.

    Now, there is no AutoTextEntries collection of the ActiveDocument, so your original proposal doesn't work. Your two options are the one set out by Stuart, and the "manual" method of entering the code in the document, assigning a range object to it, and using the Range.InsertAutoText method. You might think you could use the dialogs collection to change the drop-down, but it doesn't seem to work using what seems to me to be the most obvious code:

    With Dialogs(wdDialogEditAutoText)
    .Context = 0 '0 = Normal, 1 = Attached, 2+ = Global
    End With

    And because you can't specify the template by name, this concept is just really messy. Since you want the top item on the list, you can use SendKeys. This is potentially unreliable, and it creates a screen flash, but it kinda works if you are unable to switch to the other method:

    With Dialogs(wdDialogEditAutoText)
    SendKeys "%L{PGUP}{TAB}{ENTER}"
    .Display 10
    End With

    I think in general it is best to choose extremely unique and/or improbable names when naming AutoText entries in global templates, and use the explicit insertion method. Otherwise, as you discovered, the results may not be what you expect. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Added: The SendKeys seems to have a bad side effect of making the next dialog you open also flash and disappear (Word 2002 SP3 with GDI+ patch). Obviously this is just a little bug, right? But a very, very annoying one. Be forewarned!

  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: Specify which templates Autocorrect can use? (

    Hi Jefferson, thanks for trying, and it looks like you got basically the same result I did - Word won't let you do it like that (although you found more possible ways to try than I did!).

    And yet it seems such a simple thing to want to do!

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> Guess it's back to the old "forget to change it back > sub crashes > change it back manually > try again" routine I've been using all this week. Yes, the autotext entries are identical (I accidentally saved it without changing to definite template once and now it won't let me get rid of it again!); I guess I'll just have to buckle down to getting rid of it properly on Monday!
    Beryl M


Posting Permissions

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