Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    error 5941 (xpp mso2003)

    Hi
    Sometime ago I created a global report template for our assessors. As part of the reporting they raise corrective action requests. To do this they click on a custom toolbar to insert a CAR. When they have finshed they have to number the CARs. I have created a macro that asks how many CARs were raised, inserts the apprpriate "autotext" depening on whether there were 0, 1 or >1 and inserts the number at a bookmark.

    Suddenly staff are getting this error message. "Runtime error 5941: The requested member of the collection does not exist" and only an option to end the macro.

    I have checked all the code and everything seems OK.

    Sub NumberCARs()

    Dim strTemp As String
    Dim bmRange As Range

    Application.ScreenUpdating = False

    strTemp = InputBox("Enter the number of CARs")
    If Trim(strTemp) <> vbNullString Then
    If ActiveDocument.Bookmarks.Exists("rptTotalCARs") = True Then
    Selection.GoTo What:=wdGoToBookmark, Name:="rptTotalCARs"
    Else
    Selection.GoTo What:=wdGoToBookmark, Name:="NoCAR"
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.EndKey Unit:=wdLine
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=" "
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:="rptTotalCARs"
    .DefaultSorting = wdSortByName
    .ShowHidden = False
    End With
    End If

    If strTemp = "0" Then

    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"

    ActiveDocument.AttachedTemplate.AutoTextEntries( _
    "No CARs").Insert Where:=Selection.Range, _
    RichText:=True

    strTemp = vbNullString

    Else
    If strTemp = 1 Then
    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"
    ActiveDocument.AttachedTemplate.AutoTextEntries( _
    "One CAR").Insert Where:=Selection.Range, _
    RichText:=True

    strTemp = vbNullString

    Else
    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"
    ActiveDocument.AttachedTemplate.AutoTextEntries("M ulti CARs").Insert Where _
    :=Selection.Range, RichText:=True

    Set bmRange = ActiveDocument.Bookmarks("rptTotalCARs").Range
    bmRange.Text = strTemp
    ActiveDocument.Bookmarks.Add ("rptTotalCARs"), bmRange
    End If
    End If
    End If

    End Sub

    Can anyone give me any idea as to what is happening?

    cheers
    cheers

    Phil Carter

  2. #2
    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 (xpp mso2003)

    Can you confirm that the bookmarks exist in the document and that the AutoText entries are in the AttachedTemplate?

  3. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: error 5941 (xpp mso2003)

    Jefferson hi

    Yes I can confirm the bookmarks for inserting the autotext are in the document(s about 30) but the bookmark "rptTotalCARs" is part of the autotext where required
    cheers

    Phil Carter

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

    Re: error 5941 (xpp mso2003)

    Try single-stepping through the macro (F8) to see where exactly the error occurs.

  5. #5
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: error 5941 (xpp mso2003)

    Hans hi

    Its been a while since I posted this problem but I have finally, after illness, got around to checking this code.

    The code stops at this point

    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"
    ActiveDocument.AttachedTemplate.AutoTextEntries("M ulti CARs").Insert Where _
    :=Selection.Range, RichText:=True

    It seems, for some reason, it believes the Autotext entries don't exist. I have tried recreating them but still doesn't work. The Autotext entries are included in a global template that is located in the startup folder.

    I don't understand this as it worked fine previousely (I can't be more specific as I don't use as often as some other staff).

    cheers
    cheers

    Phil Carter

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

    Re: error 5941 (xpp mso2003)

    ActiveDocument.AttachedTemplate.AutoTextEntries("Multi CARs") makes VBA look for the autotext entry in the template that the document is based on. Since you state that the autotext entry is stored in a global template, the code won't find it. Try this code to insert the autotext entry:

    Dim tmp As Template
    For Each tmp In Templates
    If tmp.Name = "TaskPaneController.dot" Then
    tmp.AutoTextEntries("Multi CARs").Insert Where:=Selection.Range, RichText:=True
    Exit For
    End If
    Next tmp

  7. #7
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: error 5941 (xpp mso2003)

    Hans thanks for that

    When numbering the CARs in the report there are 3 options 0, 1 or >1. Your code works great for >1 but not for the other options.
    cheers

    Phil Carter

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

    Re: error 5941 (xpp mso2003)

    Have you changed the code for all three cases?

  9. #9
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: error 5941 (xpp mso2003)

    Yes
    cheers

    Phil Carter

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

    Re: error 5941 (xpp mso2003)

    Then check very carefully that the autotext entries you need are actually stored in the global template you specify in the code. If so, make sure that you are using the correct names.

  11. #11
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: error 5941 (xpp mso2003)

    Hans

    I have checked the exitance and speling of all the autotext entries. They all exist and match.

    Here is the entire code:
    Sub NumberCARs()

    Dim strTemp As String
    Dim bmRange As Range
    Dim tmp As Template

    Application.ScreenUpdating = False

    strTemp = InputBox("Enter the number of CARs")
    If Trim(strTemp) <> vbNullString Then
    If ActiveDocument.Bookmarks.Exists("rptTotalCARs") = True Then
    Selection.GoTo What:=wdGoToBookmark, Name:="rptTotalCARs"
    Else
    Selection.GoTo What:=wdGoToBookmark, Name:="NoCAR"
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.EndKey Unit:=wdLine
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=" "
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    With ActiveDocument.Bookmarks
    .Add Range:=Selection.Range, Name:="rptTotalCARs"
    .DefaultSorting = wdSortByName
    .ShowHidden = False
    End With
    End If

    If strTemp = "0" Then

    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"
    For Each tmp In Templates
    If tmp.Name = "TaskPaneController.dot" Then
    tmp.AutoTextEntries("No CARs").Insert Where:=Selection.Range, RichText:=True
    Exit For
    End If
    Next tmp

    strTemp = vbNullString

    Else
    If strTemp = 1 Then
    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"
    For Each tmp In Templates
    If tmp.Name = "TaskPaneController.dot" Then
    tmp.AutoTextEntries("One CAR").Insert Where:=Selection.Range, RichText:=True
    Exit For
    End If
    Next tmp

    strTemp = vbNullString

    Else
    Selection.GoTo What:=wdGoToBookmark, Name:="NumberCARs"
    For Each tmp In Templates
    If tmp.Name = "TaskPaneController.dot" Then
    tmp.AutoTextEntries("Multi CARs").Insert Where:=Selection.Range, RichText:=True
    Exit For
    End If
    Next tmp

    Set bmRange = ActiveDocument.Bookmarks("rptTotalCARs").Range
    bmRange.Text = strTemp
    ActiveDocument.Bookmarks.Add ("rptTotalCARs"), bmRange
    End If
    End If
    End If

    End Sub
    cheers

    Phil Carter

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

    Re: error 5941 (xpp mso2003)

    The name TaskPaneController.dot in my code was just meant as an example - it is the name of the only global template I have installed, so it came in handy here. But I doubt that it is the name of the global template in which you have stored the autotext entries, since it is a third-party global template. You should use the name of the global template in which the autotext entries are stored.

  13. #13
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: error 5941 (xpp mso2003)

    Doh!

    Yep that makes a big difference.

    Thanks again Hans
    cheers

    Phil Carter

Posting Permissions

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