|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
试试下面的效果:
- Sub 隐藏()
- ActiveDocument.ActiveWindow.View.ShowHiddenText = False
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = "【*】"
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- If Not Selection.Type = wdSelectionIP Then
- If .End > Selection.End Then Exit Do
- End If
- For i = 1 To CountZh(.Text)
- .Text = Left(.Text, Len(.Text) - 1) & " " & "】"
- Next
- For Each a In .Characters
- If a <> "【" And a <> "】" And a <> " " Then a.Font.Hidden = True
- Next
- .Start = .End
- End With
- Loop
- End With
- End Sub
- Sub 显示()
- ActiveDocument.ActiveWindow.View.ShowHiddenText = True
- ActiveDocument.Content.Font.Hidden = False
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = "【*】"
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- If Not Selection.Type = wdSelectionIP Then
- If .End > Selection.End Then Exit Do
- End If
- .Text = Replace(.Text, " ", "")
- .Start = .End
- End With
- Loop
- End With
- End Sub
- Function CountZh(ByVal sZh As String) As Integer
- Dim reg, matches
- Set reg = CreateObject("VBScript.RegExp")
- reg.Pattern = "[\u4e00-\u9fa5]"
- reg.Global = True
- reg.IgnoreCase = True
- Set matches = reg.Execute(sZh)
- CountZh = matches.Count + Len(sZh) - 2
- Set reg = Nothing
- End Function
复制代码
|
|