G
Greg Maxey
I was working with a macro that Klaus Linke posted the other day to remove
unused styles. Klaus explains that Normal, DefaultParagraph, and Heading1-9
sytles are built in and can't be removed. I have Word2003 and in my
Normal.dot there are two other styles that can't be removed: NormalTable
and NoList.
I added a line to Klaus' code to handle the NormalTable (skip it), but when
I tried to add a constant for the NoList style I could't fine one. I use
wdStyleNormalTable for the normal table, I looked through all of the
wdStyle constants and couldn't find one for NoList. I didn't try each one
as none looked promising. I would like to add a line in the below code
similiar to the Case statements for NormalTable and the other builtin
styles. Can anyone suggest what I should use? Thanks.
Sub DeleteUnusedStyles()
Dim oDoc As Document
Dim myStyle As Style
Dim myString As String
Dim i As Integer
Set oDoc = ActiveDocument
For Each myStyle In oDoc.Styles
If myStyle.InUse Then
Select Case myStyle
Case oDoc.Styles(wdStyleDefaultParagraphFont)
Case oDoc.Styles(wdStyleNormal)
Case oDoc.Styles(wdStyleNormalTable)
Case oDoc.Styles(wdStyleHeading1) To oDoc.Styles(wdStyleHeading9)
Case Else
Selection.Collapse (wdCollapseStart)
With Selection.Find
.ClearFormatting
.Style = myStyle
.Forward = True
.Wrap = wdFindContinue
.Execute FindText:="", Format:=True
If .Found = False Then
StatusBar = myStyle.NameLocal
If MsgBox("Delete", vbYesNo, myStyle.NameLocal) = vbYes Then
myStyle.Delete
End If
Else
myString = myString + myStyle.NameLocal & vbCr
End If
End With
End Select
End If
Next myStyle
MsgBox "In addition to Builtin styles, the" _
& vbCr & "following style(s) can't be removed:" & vbCr & myString
End Sub
unused styles. Klaus explains that Normal, DefaultParagraph, and Heading1-9
sytles are built in and can't be removed. I have Word2003 and in my
Normal.dot there are two other styles that can't be removed: NormalTable
and NoList.
I added a line to Klaus' code to handle the NormalTable (skip it), but when
I tried to add a constant for the NoList style I could't fine one. I use
wdStyleNormalTable for the normal table, I looked through all of the
wdStyle constants and couldn't find one for NoList. I didn't try each one
as none looked promising. I would like to add a line in the below code
similiar to the Case statements for NormalTable and the other builtin
styles. Can anyone suggest what I should use? Thanks.
Sub DeleteUnusedStyles()
Dim oDoc As Document
Dim myStyle As Style
Dim myString As String
Dim i As Integer
Set oDoc = ActiveDocument
For Each myStyle In oDoc.Styles
If myStyle.InUse Then
Select Case myStyle
Case oDoc.Styles(wdStyleDefaultParagraphFont)
Case oDoc.Styles(wdStyleNormal)
Case oDoc.Styles(wdStyleNormalTable)
Case oDoc.Styles(wdStyleHeading1) To oDoc.Styles(wdStyleHeading9)
Case Else
Selection.Collapse (wdCollapseStart)
With Selection.Find
.ClearFormatting
.Style = myStyle
.Forward = True
.Wrap = wdFindContinue
.Execute FindText:="", Format:=True
If .Found = False Then
StatusBar = myStyle.NameLocal
If MsgBox("Delete", vbYesNo, myStyle.NameLocal) = vbYes Then
myStyle.Delete
End If
Else
myString = myString + myStyle.NameLocal & vbCr
End If
End With
End Select
End If
Next myStyle
MsgBox "In addition to Builtin styles, the" _
& vbCr & "following style(s) can't be removed:" & vbCr & myString
End Sub