如果文档包含任何突出显示,我正在尝试编写一个宏,当用户单击保存时会显示弹出窗口(我将其作为Sub FileSave())。到目前为止,消息框一切正常。不幸的是,我无法弄清楚if语句使用哪些条件来检查文档是否包含突出显示。
有人可以为我提供几行VBA吗?
答案 0 :(得分:0)
您只需要以这种方式在文档内容中搜索突出显示的文本:
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