Hidden Text Using Checkbox

D

Dave

Hello,
I'm trying to write a macro that will toggle text in a bookmark between
hidden and unhidden using a checkbox. I still need the text visible on
screen, but I just don't want the text to print. I managed to make it work
one time, but something must have gone wrong in my code. Does anyone have a
better suggestion or can spot what I'm doing wrong. My macro is below.

Sub mcr1A()

ActiveDocument.Unprotect Password:=""

Set vCheck1 = ActiveDocument.FormFields("chk1A").Range

If vCheck1 = False Then
ActiveDocument.Bookmarks("bk1A").Select
With Selection.Font
.Hidden = True
End With
End If

ActiveDocument.Protect Password:="", NoReset:=True, Type:= _
wdAllowOnlyFormFields

End Sub
 
D

Doug Robbins

You don't say what doesn't work any more. Maybe the problem is with the
settings under Tools>Options>View or Tools>Options>Print which are what
control the display/printing of hidden text.

I don't see anything wrong with your code, but better to use

ActiveDocument.Bookmarks("bk1A").Range.Font.Hidden = True

as it does not require the movement of the insertion point.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Dave

Thanks Doug!! I should have elaborated.
When this macro is ran, the font does not change to hidden.
Seems like the problem is this line of code:
Set vCheck1 = ActiveDocument.FormFields("chk1A").Range

When I add a break to the code following this line, the value of vCheck is
neither True or False. I'm new to the word programming, should I not have
this macro run on exit?
 
D

Doug Robbins

You need to use the following construction:

Set vCheck1 = ActiveDocument.FormFields("chk1A").CheckBox.Value


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top