【问题标题】:How to unhighlight the text before closing the Document如何在关闭文档之前取消突出显示文本
【发布时间】:2016-11-04 06:32:15
【问题描述】:

我有一个要求,它应该算数。词句明智的。如果不。句子中的单词超过20个,它应该突出它。 & 当用户关闭文档时。这个突出显示应该消失。下面是我使用的代码。它在数数。单词然后突出显示也正确。但是,当用户关闭该文档时如何取消突出显示?

Sub Count_of_words()
'
' Count Macro
'
'
    Dim s As Range
    For Each s In Selection.Sentences
        If s.Words.count > 20 Then
            With s.Font
                .Underline = wdUnderlineWavy
                .UnderlineColor = wdColorRed
            End With         
        End If
    Next
End Sub

【问题讨论】:

    标签: vba macros ms-word


    【解决方案1】:

    您可以使用 Document_Close() 事件 - 只需将代码放入其中,它将在文档关闭之前执行 - 您可以使用原始代码,但 .Underline = wdUnderlineWavy 和 .UnderlineColor = wdColorRed 使用不使用的值突出显示文本。事件过程必须在 ThisDocument 文件中,而不是在模块文件中(您可以在 Project Explorer 中找到它)。所以,基本上,打开 ThisDocument 并编写程序:

    Sub Document_Close()
    '
    ' Count Macro
    '
    '
    
    Dim s As Range
    For Each s In Selection.Sentences
        If s.Words.count > 20 Then
        With s.Font
                    .Underline = 'put code to no underline
                    .UnderlineColor = 'put code to no color
                End With
    
    
    End If
    
    Next
    
    End Sub
    

    【讨论】:

    • 我使用了 Document_Close() 事件并将该事件存储在模板中。然后我将该模板设为全局。它不适用于全球。
    • 当我关闭 Word 文档时,它不会为我触发 Document_Close()。
    • 尝试使用 Private Sub Document_Close() 而不是 Sub Document_Close(),或者从 visualBasic 编辑器顶部的组合框中选择此过程,也许会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多