Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Deleting Styles with VBA (Word 2003)

    I'm having some difficulties with author styles in Word giving me fits when I try to apply different styles. Sometimes the old attributes are still present. This is resolved by deleting the original, unneeded style. This happens so much that I think I need to write a quick macro to delete them. I'm not certain if I only need delete certain ones or delete all that word will allow in one sweep. I tried recording one, but it wouldn't work correctly . Can anyone give me tips on how to accomplish this?

  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: Deleting Styles with VBA (Word 2003)

    I believe we have had some threads in the past for macros that deleted "unused" styles. I suggest searching both Word and VB/VBA for those.

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

    Re: Deleting Styles with VBA (Word 2003)

    You could use this:

    ' Suppress error if styles don't exist or can't be deleted
    On Error Resume Next
    ActiveDocument.Styles("_NoterefInNote").Delete
    ActiveDocument.Styles("_AnotherStyle").Delete
    ActiveDocument.Styles("YetAnotherOne").Delete

  4. #4
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Deleting Styles with VBA (Word 2003)

    This is what I came up with, but I still can't get it to work.

    Dim styleLoop As Style

    For Each styleLoop In ActiveDocument.Styles
    If styleLoop = "_NoteRefinNote" Then
    ActiveDocument.OrganizerDelete Source:=ActiveDocument, Name:="_NoterefInNote", Object:=wdOrganizerObjectStyles
    End If
    Next styleLoop

    When stepping through it, it doesn't process the "ActiveDocument.... " line. I thought at first that I had mispelled the style I wanted to delete, but I did not. Is there some list collection that I'm not getting right??

    Any help you can give would be appreciated.

  5. #5
    Star Lounger
    Join Date
    Nov 2003
    Posts
    61
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Deleting Styles with VBA (Word 2003)

    That worked!! You're the stud. [img]/forums/images/smilies/smile.gif[/img]

  6. #6
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deleting Styles with VBA (Word 2003)

    I've reworked the macro I posted three years ago, to take into account the new list styles, table styles, and linked styles in Word2002/2003 (appended).

    You can comment out the message boxes if you find you regularly want to delete all unused styles. I usually like to check whether I want to keep them, individually.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus
    Attached Files Attached Files

Posting Permissions

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