Word VBA:.Hide 函数不隐藏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8603328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:45:38  来源:igfitidea点击:

Word VBA: .Hide function doesn't hide?

vbams-officeword-vba

提问by J4N

I took an old MS Word document to adapt it with a new layout.

我拿了一个旧的 MS Word 文档来调整它的新布局。

I finished last week and everything was working fine, the main macro has to hide or display some text.

我上周完成了,一切正常,主宏必须隐藏或显示一些文本。

For this, a zone of text is "bookmarked", and then we get this bookmark and set its font to hidden:

为此,文本区域被“添加书签”,然后我们获取此书签并将其字体设置为隐藏:

ActiveDocument.Bookmarks("MyBookMarkname").Range.Font.Hidden = True 'Or False

It's how it was done on the old document, and I had only to do the same on the new document(recreate those bookmarks).

这是在旧文档上完成的方式,我只需要在新文档上做同样的事情(重新创建那些书签)。

But today, when trying again to make this action, the text isn't hidding anymore! When it is supposed to be hidden, the text is like underlined by a small blue line(the same line you have when an word is not spellt correctly, but in blue).

但是今天,当再次尝试执行此操作时,文本不再隐藏!当它应该被隐藏时,文本就像一个小蓝线(当一个单词拼写不正确时的同一行,而是蓝色)下划线。

I searched online, I found several things, but none of them worked:

我在网上搜索,我发现了几件事,但没有一个奏效:

Private Sub HideHiddenText()
    For Each myWindow In Windows
        myWindow.View.ShowHiddenText = False
    Next myWindow
End Sub

I've no "revision mode" enabled either.

我也没有启用“修订模式”。

What could be wrong?

可能有什么问题?

回答by joeschwa

I believe the wavy blue line that Word is displaying is being triggered by the hidden text because Word uses the blue line to mark formatting inconsistencies. To get rid of the line in Office 2007/2010 go to

我相信 Word 显示的蓝色波浪线是由隐藏文本触发的,因为 Word 使用蓝线来标记格式不一致。要摆脱 Office 2007/2010 中的行,请转到

Office Orb Menu (2007) or File Menu (2010)|Options|Advanced

Office Orb 菜单 (2007) 或文件菜单 (2010)|选项|高级

and uncheck Mark formatting inconsistencies

并取消选中标记格式不一致

The wavy blue line, however, has nothing to do with your hidden text being displayed. I believe this is happening because the "Show/hide formatting marks" function is turned on. To make sure your hidden text is kept hidden by vba, you will need the following:

但是,蓝色波浪线与显示的隐藏文本无关。我相信这是因为“显示/隐藏格式标记”功能已打开。为了确保您的隐藏文本被 vba 隐藏,您将需要以下内容:

With ActiveDocument
    .ActiveWindow.View.ShowAll = False 'Hide all formatting marks
    .ActiveWindow.View.ShowHiddenText = False 'Do not display hidden text
    .Application.Options.PrintHiddenText = False 'Do not print hidden text
End With

It is worth noting that an experienced Word user can always choose to display hidden text via Word's user interface and that if this is to be avoided, a great deal of additional work would need to be invested to disable the native Word functions that can be used to display hidden text (if that is even possible).

值得注意的是,有经验的 Word 用户始终可以选择通过 Word 的用户界面显示隐藏文本,如果要避免这种情况,则需要投入大量额外工作来禁用可以使用的 Word 原生功能显示隐藏文本(如果可能的话)。