网上最好的一个解决页面,请参阅: http://www.windowsdevcenter.com/pub/a/windows/excerpt/wdhks_1/index.html?page=2 Sub DeleteCharCharStyles( ) Dim sty As Style Dim i As Integer Dim doc As Document Dim sStyleName As String Dim sStyleReName As String Dim bCharCharFound As Boolean
Set doc = ActiveDocument Do bCharCharFound = False For i = doc.Styles.Count To 1 Step -1 Set sty = doc.Styles(i) sStyleName = sty.NameLocal If sStyleName Like "* Char*" Then bCharCharFound = True If sty.Type = wdStyleTypeCharacter Then On Error Resume Next '############################################# ' COMMENT OUT THE NEXT LINE IN WORD 2000 OR 97 sty.LinkStyle = wdStyleNormal sty.Delete Err.Clear Else sStyleReName = Replace(sStyleName, " Char", "") On Error Resume Next sty.NameLocal = sStyleReName If Err.Number = 5173 Then Call SwapStyles(sty, doc.Styles(sStyleReName), doc) sty.Delete Err.Clear Else On Error GoTo ERR_HANDLER End If End If Exit For End If Set sty = Nothing Next i Loop While bCharCharFound = True Exit Sub ERR_HANDLER: MsgBox "An Error has occurred" & vbCr & _ Err.Number & Chr(58) & Chr(32) & Err.Description, _ vbExclamation End Sub Function SwapStyles(ByRef styFind As Style, _ ByRef styReplace As Style, _ ByRef doc As Document) With doc.Range.Find .ClearFormatting .Text = ""
.Wrap = wdFindContinue .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Style = styFind .Replacement.ClearFormatting .Replacement.Style = styReplace .Replacement.Text = "^&" .Execute Replace:=wdReplaceAll End With End Function |