如何让Word检查我的文本的完整性?

时间:2013-04-16 08:13:59

标签: macros ms-word word-vba

我想自动检查我的文档中的某些属性:

  1. 括号前的空格
  2. 查找列表中指定的黄鼠狼词汇
  3. 不可打印的字符(我设置了很多方程式然后改变了类型 - 不好)
  4. 理想情况下,我想用评论来标记所有这些,所以我可以稍后修复它们。

    这种文本测试是否可行/可行/已存在于单词中?

1 个答案:

答案 0 :(得分:2)

不幸的是,您无法立即运行它,因为如果您需要某些标记,则无法突出显示隐藏的文档标记。尝试使用这两个子目标来实现不同的目标(也可以阅读subs中的一些注释)

Sub Searching_For_Text()
    'will highlight all options added with .HitHighlight method
    With ActiveDocument.Content.Find
        .ClearHitHighlight
    'words
        .HitHighlight "Variant" 'any word this way
    'any text
        .HitHighlight "  ("  'this for spaces before parenthesis 

    'partially specified text
        .HitHighlight "doc"  'simply this for words like: _
                            document, documents

    'option 2- this can't be highlighted but no error returned
        .HitHighlight "^p" 'paragraph mark
        .HitHighlight "^l" 'soft line mark
    End With
End Sub

对于特殊文件标记:

Sub Searching_Special_marks()
    'for paragraph marks you need to search each separately
    'each time you call it you will find next one, next to current selection point
    With Selection.Find

    'some cleaning
    .ClearFormatting

    'searching each separately
        .Text = "^p"    '^l for soft lines, _
                        ^t for tabs, etc.
        .Forward = True
        .Execute
    End With
End Sub

我认为您需要对这些可能的解决方案进行一些实验。

相关问题