|
Sub test()
'i=计数器,j=选定区域字长,k=循环变量
Dim i As Long, j As Long, k As Long
j = Len(Selection)
If Selection.Type = wdSelectionIP Then
MsgBox "未选定区域!", vbOKOnly + vbCritical, "替换选定区域空格为#号"
Else
If Selection Like "* *" Then
'计算选定区域空格数目
For k = 1 To j
If Selection.Characters(k).Text = " " Then i = i + 1
Next k
'替换选定区域空格为红色#号
With Selection.Find
.ClearFormatting
With .Replacement
.ClearFormatting '清除格式
.Font.Bold = True '加粗
.Font.Color = wdColorRed '红色
End With
.Execute FindText:=" ", replacewith:="#", Format:=True, Replace:=wdReplaceAll
End With
MsgBox "处理完毕!选定区域共有 " & i & " 个空格被替换为红色#号!", vbOKOnly + vbExclamation, "替换选定区域空格为#号"
Else
MsgBox "选定区域没有空格!", vbOKOnly + vbExclamation, "替换选定区域空格为#号"
End If
End If
End Sub |
评分
-
2
查看全部评分
-
|