Checkbox print macro

C

Chuck

hi all,

i have found a macro which will tell the word document to either print
or not print depending if there is a check within a checkbox

the macro seems simple and since then i have coppied the macro
accordingly to apply to ther existing checkboxes.

however, it seems that on some checkboxes (using bookmarks), that word
just will not do what i am asking it to do via the macro

this is the macro
=============
Sub Check01()

With ActiveDocument
.Unprotect

If .FormFields("Check01").CheckBox.Value = False Then
.Bookmarks("Check01Text").Range.Font.Hidden = True
Else
.Bookmarks("Check01Text").Range.Font.Hidden = False
End If

.Protect wdAllowOnlyFormFields, NoReset

End With

End Sub


Sub Check02()
With ActiveDocument
.Unprotect

If .FormFields("Check02").CheckBox.Value = False Then
.Bookmarks("Check02Text").Range.Font.Hidden = True
Else
.Bookmarks("Check02Text").Range.Font.Hidden = False
End If

.Protect wdAllowOnlyFormFields, NoReset

End With

End Sub
============

ect.. there is about 10 of these with the correct formfield names &
bookmark names. and yes, i have told each form field checkbox to run
macro on exit

can anyone advise why this only wants to work say ... 75% of the time?

cheers
 
C

Chuck

i have identified and rectified the issue

its not a coding thing. what actually needs to happen after a user
unchecks / checks a checkbox, that the user needs to click onto
another formfield .. thus enabling the macro

all works fine

cheers for anyone who tried to help prior to this
 
G

Graham Mayor

The problem appears to be attributable ambiguity in the check box/bookmark
naming. If you remove the 0s from the names it appears to work reliably.
Also, you only need one macro run on exit from the last of the check box
fields to test the value of all of them (or you could run the same macro on
exit from each to hide the text as you go along). The following will work
for 10 check box fields, named Check1 to Check10 with ten bookmarks named
Check1Text to Check10Text

Sub Check01()
Dim bProtected As Boolean
Dim i As Integer
Dim sBmark As String
Dim sCbox As String

'Unprotect the file
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
bProtected = True
.Unprotect Password:=""
End If

For i = 1 To 10 'process the 10 check boxes
sCbox = "Check" & i
sBmark = sCbox & "Text"
If .FormFields(sCbox).CheckBox.Value = False Then
.Bookmarks(sBmark).Range.Font.Hidden = True
Else
.Bookmarks(sBmark).Range.Font.Hidden = False
End If
Next i

'Reprotect the file
If bProtected = True Then
.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

Chuck

cheers for this, i will give this a shot.. hopefully i can figure what
you are saying (macro newbe)
 

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