Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error 5941: Autotext macro (Word 2003 SP1)

    Hi

    I have created an autotext entry which contains a Wordart Object and created a macro to insert the autotext (because it's part of a larger procedure for changing printer trays). I then used the Organiser to put the autotext and the macro into a template.

    If I have the template open for editing, the autotext works and the macro works and calls the autotext (as well as the changing of the printer trays).

    But, when I put the template into the Startup Folder and run the macro in a blank document, it halts on the line which calls the Autotext:

    ActiveDocument.AttachedTemplate.AutoTextEntries("w mcopy2").Insert Where:= Selection.Range, RichText:=True

    and the following message appears:

    "Runtime error 5941
    The requested member of the collection does not exist"

    Help please.

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

    Re: Error 5941: Autotext macro (Word 2003 SP1)

    You say that the Autotext is in a template in the Startup folder, but the code seems to be looking for it in the AttachedTemplate.

    What is the Attached Template? Is it the correct place?

    StuartR

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error 5941: Autotext macro (Word 2003 SP1)

    It's in the startup folder identified under Tools/Options, and it then shows up under Tools/Templates and Addins/Global Templates and Addins. So I presume it's in the correct place?

    Nick

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

    Re: Error 5941: Autotext macro (Word 2003 SP1)

    But does it show up as the "Document Template" in templates and add ins? The line of code that you showed won't look in every template in the Startup folder, just in the one specified as the document template.

    If the Autotext is in the same template as the Macro that is looking for it then try using

    <code>MacroContainer.AutoTextEntries("wmcopy2").In sert Where:= Selection.Range, RichText:=True</code>
    instead of
    <code>ActiveDocument.AttachedTemplate.AutoTextEntr ies("wmcopy2").Insert Where:= Selection.Range, RichText:=True</code>

    StuartR

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Sydney, New South Wales, Australia
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error 5941: Autotext macro (Word 2003 SP1)

    I worked it out.

    I tried your solution: no go.

    Neither did this:
    Selection.TypeText Text:="wmdraft2"
    Selection.Range.InsertAutoText

    But this one did:
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "AUTOTEXT WMDRAFT2 ", PreserveFormatting:=True

    Thanks for your help
    Nick

  6. #6
    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: Error 5941: Autotext macro (Word 2003 SP1)

    I think there is a difference between inserting an AutoText entry and an AutoText field. In particular, if that field is refreshed in an environment where the Autotext entry is not available, its content might become invalid and go missing. To avoid this, you might use the syntax:

    Set fldMyNewField = Selection.Fields.Add etc.
    fldMyNewField.Unlink

    This will convert the Autotext field to its results.

Posting Permissions

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