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

    Error 5101 (wxpp sp3 mso2003)

    Hi
    I have some code to update the styles in older documents. it has worked fine in the past, but now returns the "runtime error '5101', cannot locate bookmark.

    The code I have been using ( mostly supplied by Hans) is;
    Sub StyleCopy()
    '
    ' stylecopy Macro
    ' Macro recorded 10/11/2006
    ' Modified 13/11/2006 to add code supplied by HansV and Andrew Lockton
    '
    Dim i As Integer
    For i = ActiveDocument.Styles.Count To 1 Step -1
    If ActiveDocument.Styles(i).BuiltIn = False Then
    ActiveDocument.Styles(i).Delete
    Debug.Print ActiveDocument.Styles(i)
    End If
    Next i
    ActiveDocument.UpdateStyles

    With ActiveDocument
    .AttachedTemplate = "Normal.dot"

    .UpdateStylesOnOpen = True
    .UpdateStyles

    End With
    End Sub

    Can anyone see nay problems with this as I don not actually look for nay bookmarks!
    cheers

    Phil Carter

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

    Re: Error 5101 (wxpp sp3 mso2003)

    Which line causes the error?

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Error 5101 (wxpp sp3 mso2003)

    You haven't specified which line is causing the error but here are a few random thoughts for you.

    Firstly, the debug.print line is trying to return something that you deleted in the previous line. You might want to move that line in front of the Delete line.

    Next, do you really need to refresh the styles from two different templates? The first UpdateStyles will import styles from the attached template and then you change the template before importing the styles from Normal.dot. The styles in Normal that appear in the other template will be overwritten by those in Normal.

    Finally, where is the code when you run it. If you detach the template as part of the code then you want to be sure that the code is not contained in the attached template.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

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

    Re: Error 5101 (wxpp sp3 mso2003)

    Hans sorry

    I was a bit vaque. This line is thew line that is highlighted when the error shows;

    ActiveDocument.Styles(i).Delete
    cheers

    Phil Carter

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

    Re: Error 5101 (wxpp sp3 mso2003)

    I don't see why that line would cause an error. Could you post a document that displays this error? You can remove most or all of the text from the document.

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

    Re: Error 5101 (wxpp sp3 mso2003)

    Hans

    As requested the document I am currently working on
    Attached Files Attached Files
    cheers

    Phil Carter

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

    Re: Error 5101 (wxpp sp3 mso2003)

    I don't get an error 5101 when I try to run the code in your document. Instead I get error 5122 when trying to delete the style " Char"; the error message says that this style is not found. This is one of the notorious " Char" styles, you may be able to get rid of it using the Organizer, but not the normal way.

    I recommend turning off "Keep track of formatting" in the Edit tab of Tools | Options...
    The "Keep track of formatting" option is the source of the evil " Char" styles.

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

    Re: Error 5101 (wxpp sp3 mso2003)

    Hans

    Your right there are 2 "Char" styles in the document.
    I tried to delete them but could not. What is "Delette but not the normal way"?
    cheers

    Phil Carter

  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 5101 (wxpp sp3 mso2003)

    Hans hi

    I have found that for some reason I had combined the code from 2 different modules, one for copying the styles from normal.dot and the other to remove any non-standard styles.

    The style copy module works just fine. However, the style update module returns a 4198 error when run but when I step thorugh, to see where it fails it works fine and remove all extraneuos styles!

    Sub StyleUpdate()

    Dim i As Integer
    For i = ActiveDocument.Styles.Count To 1 Step -1
    If ActiveDocument.Styles(i).BuiltIn = False Then
    Debug.Print ActiveDocument.Styles(i)
    ActiveDocument.Styles(i).Delete
    End If
    Next i
    ActiveDocument.UpdateStyles

    End Sub

    Again if it fails it is at the line ActiveDocument.Styles(i).Delete


    Any ideas?
    cheers

    Phil Carter

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

    Re: Error 5101 (wxpp sp3 mso2003)

    Search the Word forum for char styles, or see Hacking Word | O'Reilly Media.

  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 5101 (wxpp sp3 mso2003)

    Hans cheers

    I had to run the hack first and then update styles.
    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
  •