如果文档包含任何突出显示,我正在尝试编写一个宏,当用户单击保存时显示一个弹出窗口(我将它作为 Sub FileSave() )。到目前为止,消息框一切正常。不幸的是,我无法弄清楚 if 语句使用哪些条件来检查文档是否包含突出显示。
任何人都可以为此提供几行 VBA 帮助我吗?
您只需以这种方式在文档内容中搜索突出显示的文本:
Sub SearchAnyHighlight()
Dim hiliRng As Range
Set hiliRng = ActiveDocument.Content
With hiliRng.Find
.Highlight = True
.Execute
End With
If hiliRng.Find.Found Then
'to inform that something was found
MsgBox "You can't close Active Document"
'to remove all highlighted area <-- added after edition
With hiliRng.Find
.Replacement.Highlight = False
.Execute "", Replace:=wdReplaceAll, Forward:=True, _
ReplaceWith:="", Format:=True
End With
End If
End Sub