PDA

View Full Version : Show /Hide Bookmarked text with Togglebuttons



quant2009
04-05-2013, 04:00 AM
Hi all, would be grateful if someone could point out what I'm missing here.

Creating a doc' where blocks of text are hidden or shown according to user preference with togglebuttons for each block of text. Code as follows:-

Sub ShowHideBookmark()
Dim para1 As Range, para2 As Range
Set para1 = ActiveDocument.Bookmarks("CWIND_DETAIL").Range
Set para2 = ActiveDocument.Bookmarks("DLG_DETAIL").Range
If ToggleButton1.Value = False Then
With para1.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
End With
Else
With para1.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
End With
End If

If ToggleButton2.Value = False Then
With para2.Font
.Hidden = True
End With
With ActiveWindow.View
.ShowHiddenText = False
End With
Else
With para2.Font
.Hidden = False
End With
With ActiveWindow.View
.ShowHiddenText = True
End With
End If
End Sub


However, when I click one button to show or hide the text, both the blocks of text are shown or hidden - so each toggle button activates all the bookmarks. I need to attribute a further 3 togglebuttons (5 in total) to specific blocks of bookmarked text. Any suggestions would be very much appreciated.

macropod
04-05-2013, 05:35 AM
Trying to toggle the display of text via the 'hidden' attribute is a waste of time if the document is to be used by others or on a different PC. That's because no matter what you do, the display and/or printing of hidden text is a user-controlled Word setting, not a document property.

quant2009
04-05-2013, 06:26 AM
Trying to toggle the display of text via the 'hidden' attribute is a waste of time if the document is to be used by others or on a different PC. That's because no matter what you do, the display and/or printing of hidden text is a user-controlled Word setting, not a document property.


Ok thanks for that. New to all of this so trying to teach myself. Thought ths may work from what I have read elsewhere but your response is much appreciated. Thank you.

fumei
04-05-2013, 03:24 PM
Also, as you have noticed showing (or hiding) the hidden font through ActiveWindow.View is global, it affects everything.

macropod
04-05-2013, 03:29 PM
For a demonstration of conditionally inserting/deleting text & formfields, see: http://www.msofficeforums.com/word/11712-noob-question.html#post30792