看似小问题,里面还真复杂。不是很满意,有空重新修订一下。 Sub Rep()
Dim Countx As Integer, i As Integer, Sh As Byte
Countx = 0
On Error Resume Next
Application.ScreenUpdating = False
With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute(FindText:="""", Forward:=True, Format:=True) = True
Countx = Countx + 1
Loop
'MsgBox Countx
Sh = Countx Mod 2
If Sh <> 0 Then
MsgBox "引号不对称!"
Exit Sub
Else
MsgBox "共有" & Countx / 2 & "对引号将被替换!"
End If
End With
For i = 1 To Countx
Sh = i Mod 2
If Sh <> 0 Then
With ActiveDocument.Content.Find
.Text = """"
.ClearFormatting
.Replacement.Text = "前引号"
.Replacement.ClearFormatting
.Execute Replace:=wdReplaceOne, Forward:=True
'MsgBox "sh=" & Sh
End With
Else
With ActiveDocument.Content.Find
.Text = """"
.ClearFormatting
.Replacement.Text = "后引号"
.Replacement.ClearFormatting
.Execute Replace:=wdReplaceOne, Forward:=True
'MsgBox "sh=" & Sh
End With
End If
Next
With ActiveDocument.Content.Find
.Text = "前引号"
.ClearFormatting
.Replacement.Text = "“"
.Replacement.ClearFormatting
.Execute Replace:=wdReplaceAll, Forward:=True
End With
With ActiveDocument.Content.Find
.Text = "后引号"
.ClearFormatting
.Replacement.Text = "”"
.Replacement.ClearFormatting
.Execute Replace:=wdReplaceAll, Forward:=True
End With
'ActiveDocument.Content.CharacterWidth = wdWidthFullWidth
Application.ScreenUpdating = True
End Sub
|