J4N
J4N

Reputation: 20727

Word VBA: .Hide function doesn't hide?

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

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?

Upvotes: 1

Views: 6951

Answers (1)

joeschwa
joeschwa

Reputation: 3175

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

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

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:

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).

Upvotes: 3

Related Questions