Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Checkbox print macro
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 |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Checkbox print macro
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 |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Checkbox print macro
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 |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Checkbox print macro
cheers for this, i will give this a shot.. hopefully i can figure what
you are saying (macro newbe) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro based off of checkbox | Microsoft Word Help | |||
Macro for open specific file from checkbox or drop-down | Microsoft Word Help | |||
MACRO for CHECKBOX FORM FIELD | Microsoft Word Help | |||
Hyperlink macro assigned to checkbox form field | Microsoft Word Help | |||
Search for Checkbox Form field in a macro | Microsoft Word Help |