PC Review


Reply
Thread Tools Rate Thread

Checkbox print macro

 
 
Chuck
Guest
Posts: n/a
 
      30th Oct 2007
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

 
Reply With Quote
 
 
 
 
Chuck
Guest
Posts: n/a
 
      30th Oct 2007
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

 
Reply With Quote
 
Graham Mayor
Guest
Posts: n/a
 
      30th Oct 2007
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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Chuck wrote:
> 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



 
Reply With Quote
 
Chuck
Guest
Posts: n/a
 
      31st Oct 2007
cheers for this, i will give this a shot.. hopefully i can figure what
you are saying (macro newbe)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox re-aligns after print or print preview =?Utf-8?B?Tm9ycmluMDE=?= Microsoft Excel Misc 1 14th Jul 2006 03:24 PM
A Print Button macro that is based on Checkbox macros Mstr G Microsoft Excel Misc 3 16th Nov 2004 11:55 PM
A Print Button macro that is based on Checkbox macros Mstr G Microsoft Excel Programming 3 16th Nov 2004 11:55 PM
Master-Detail Datagrid -checkbox (once tick the checkbox, all the child checkbox is ticked) Agnes Microsoft VB .NET 0 16th Aug 2004 11:23 AM
checkbox print ray Microsoft Access Reports 2 22nd Jun 2004 01:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:09 PM.