H
Henslow
I had a macro that in Word 2002, would delete any styles in a document that
were not in use (shown below). Now when I try to run it in 2003, I get an
error message that "myStyle" (the variable) is not found. Does anyone know
the fix for this problem?
Thanks,
-dz
Sub DeleteUnusedStyles()
Dim myStyle As Style
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Before running this procedure, it is wise to save your file. Hit OK
to continue macro or Cancel to save file." ' Define message.
Style = vbOKCancel + vbExclamation '+ vbDefaultButton2 ' Define buttons.
Title = "Save your file." ' Define title.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbCancel Then ' User chose Yes.
GoTo bye
'MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "OK" ' Perform some action.
End If
For Each myStyle In ActiveDocument.Styles
If myStyle.InUse Then
' For sleep = 1 To 405000000
' Next sleep
Select Case myStyle
Case ActiveDocument.Styles(wdStyleDefaultParagraphFont)
Case ActiveDocument.Styles(wdStyleNormal)
Case ActiveDocument.Styles(wdStyleHeading1) To _
ActiveDocument.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
' MsgBox "Delete", vbOKOnly, myStyle.NameLocal
myStyle.Delete
' Else
' MsgBox "Selected?", vbOKOnly, myStyle.NameLocal
' End
End If
End With
End Select
End If
Next myStyle
bye:
Selection.Find.ClearFormatting
End Sub
were not in use (shown below). Now when I try to run it in 2003, I get an
error message that "myStyle" (the variable) is not found. Does anyone know
the fix for this problem?
Thanks,
-dz
Sub DeleteUnusedStyles()
Dim myStyle As Style
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Before running this procedure, it is wise to save your file. Hit OK
to continue macro or Cancel to save file." ' Define message.
Style = vbOKCancel + vbExclamation '+ vbDefaultButton2 ' Define buttons.
Title = "Save your file." ' Define title.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbCancel Then ' User chose Yes.
GoTo bye
'MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "OK" ' Perform some action.
End If
For Each myStyle In ActiveDocument.Styles
If myStyle.InUse Then
' For sleep = 1 To 405000000
' Next sleep
Select Case myStyle
Case ActiveDocument.Styles(wdStyleDefaultParagraphFont)
Case ActiveDocument.Styles(wdStyleNormal)
Case ActiveDocument.Styles(wdStyleHeading1) To _
ActiveDocument.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
' MsgBox "Delete", vbOKOnly, myStyle.NameLocal
myStyle.Delete
' Else
' MsgBox "Selected?", vbOKOnly, myStyle.NameLocal
' End
End If
End With
End Select
End If
Next myStyle
bye:
Selection.Find.ClearFormatting
End Sub