![]() |
|
|
|
#1
|
||||
|
||||
|
This will not work unless the area the bookmarks are in are in an unprotected part of the form. Once you protect the form, you can only write to the form fields.
If the bookmarks are in an unprotected part of the form you can run a macro on exit from the check boxes e.g. for Checkbox1 Code:
Sub Check1_onExit()
If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
AutoTextToBM "bmAutoText1", ActiveDocument.AttachedTemplate, "Autotext1"
Else
FillBM "bmAutoText1", ""
End If
lbl_Exit:
Exit Sub
End Sub
Private Sub FillBM(strbmName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
With ActiveDocument
On Error GoTo lbl_Exit
Set oRng = .Bookmarks(strbmName).Range
oRng.Text = strValue
oRng.Bookmarks.Add strbmName
End With
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
Private Sub AutoTextToBM(strbmName As String, oTemplate As Template, strAutotext As String)
'strBMName is the name of the bookmark to fill
'oTemplate is the template with the autotext - probably ActiveDocument.AttachedTemplate
'strAutotext is the name of the autotext entry
Dim oRng As Range
On Error GoTo lbl_Exit
With ActiveDocument
Set oRng = .Bookmarks(strbmName).Range
Set oRng = oTemplate.AutoTextEntries(strAutotext).Insert _
(Where:=oRng, RichText:=True)
.Bookmarks.Add Name:=strbmName, Range:=oRng
End With
lbl_Exit:
Exit Sub
End Sub
One way which may work (though it potentially leaves the text open to view) is to insert the texts in the document and create a series of character styles - one for each check box with the hidden font attribute e.g. in the following example - the style name is Hidden1. Apply that style to the text to be hidden for checkbox 1. Code:
Sub Check1_onExit()
ActiveWindow.View.ShowHiddenText = False
If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
ActiveDocument.Styles("Hidden1").Font.Hidden = False
Else
ActiveDocument.Styles("Hidden1").Font.Hidden = True
End If
lbl_Exit:
Exit Sub
End Sub
Personally I would not use any of these hit and miss methods. The better way, given that you are going to use macros anyway is to create a userform. Put the options on the userform then build the document based on the results of the userform. The document doesn't then need to be protected, and you can use the FillBM and AutoTextToBM macros to fill the bookmarks as appropriate - either with autotexts or just text.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checkboxes in Excel | asmanokhchi | Excel | 0 | 04-28-2015 11:13 PM |
checkboxes
|
smohap | Word | 1 | 06-19-2011 09:24 PM |
Excel Checkboxes
|
theresamille699 | Excel | 3 | 04-12-2011 08:08 PM |
| Ticking Checkboxes | screid | Word | 1 | 06-08-2010 02:04 AM |
| Manipulating checkboxes in XML | Ivo | Word | 0 | 12-06-2005 09:04 AM |