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

    Style updating (Word 2010)

    We have recently upgraded to MSO 2010. In 2003 I had this code to get rid of any extraneous styles in documents created or obtained by staff.
    Sub StyleCopy()
    '
    '
    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
    With ActiveDocument
    .AttachedTemplate = "D:\Users\pgc\My Templates\Normal.dotm"
    .UpdateStylesOnOpen = True
    .UpdateStyles
    End With
    End Sub

    But for some reason the macro fails at the code indicated.
    cheers

    Phil Carter

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 28 Times in 27 Posts
    Phil,

    A few questions/comments:

    The path indicated for the location of the Normal.dotm template doesn't match what would be the default location for this template, in either Windows XP or in Windows Vista or 7.
    An error on that line of code is probably indicating that Normal.dotm does not exist at that location.

    Is D: a networked drive (in which case every user is pointing to the same Normal.dotm - not good), or is D: a local drive for each user? If the latter, is that location/path set as the user templates location for each user in each user's Word setup?

    Do you use Normal.dotm as the attached template for every document produced by staff, or do you base different documents on different templates? (because this code is attaching Normal.dotm to every document).

    Also, although you're probably aware, if you delete styles from any existing document, any text that may have had that style applied, will revert to having Normal style applied, which means this code may alter the formatting of existing documents, in unintended ways.

    Gary

  4. #3
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    472
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Gary thanks for that

    D: is a local drive that is set as the default location for the Word startup. Normal.dotm has been edited to reflect our corporate styles etc and is attahced to all docuemnts created within.

    The purpose of deleteing and updating the styles is to ensure consistency. I would like to run this macro whenever any document id opened, but that may be going a bit too far!
    cheers

    Phil Carter

  5. #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
    Quote Originally Posted by bonriki View Post
    But for some reason the macro fails at the code indicated.
    What error do you get?

  6. #5
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    472
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Jefferson hi

    VBACapture.PNG
    cheers

    Phil Carter

  7. #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
    This is not the first time I've seen that mysterious error reported when setting the AttachedTemplate property (e.g., 2 problems : Macros (Word 2000/ Word 97)), but I can't think of any reason for Word 2003 and Word 2010 to behave differently. Perhaps if the goal is to refresh the styles, you can do that another way, such as using the Style organizer to import from that template. (Assuming this is still supported in 2010.)

  8. #7
    Star Lounger
    Join Date
    Feb 2011
    Location
    Washington, DC
    Posts
    87
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Hmm. Is the "pgc" part in the path to the templates actually the same for all users? Or does that reflect your initials or something and actually should be different for each user?

    Just askin'

    - Jessica

  9. #8
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    472
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Jessica

    Yes that is me. This macro is only used by me and is only loaded on my computer
    cheers

    Phil Carter

  10. #9
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,524
    Thanks
    3
    Thanked 144 Times in 137 Posts
    Phil
    Could it the problem be that the template is already loaded as an add-in? You mentioned that the folder path was your startup folder - I would have thought that the Normal template should sit in the user templates folder and NOT in the startup where it is already loaded.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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