0
votes

I am trying to create a form template to use at work that can be customized via check boxes.

So far, I have been thinking about adding check boxes before every paragraph and at the end a button. When I click the button, my intention is to delete all the paragraphs that don't have the checkbox activated.

The problem is that I don't know which is the most user friendly approach to this. I am thinking about making bookmarks for each paragraph and use an IF formula for each of the check boxes. The most user friendly check boxes are the content control ones, but I don't know how to reference them in VBA code.

All I can find is about form field check boxes, but I don't know how to make them clickable.

Before I go studying about each of these two options, I am interested in finding out which of these two alternatives is more appropriate to fulfill my requirements.

Thank you!

1
This should help with locating content controls. - Mathieu Guindon
If I understand you correctly you want to provide the user the possibility to remove paragraphs based on his selection of check boxes. So you want to show a check box on every paragraph and allow to check or uncheck it. It kind of sounds to me like Quick Parts. Are you aware of that feature of Microsoft Word? If you use Mircosoft Word 2016 there is a Building Blocks Organizer (for Quick Parts) as well. Maybe it's worth checking out this feature: support.office.com/en-us/article/… - Bruno Bieri
@BrunoBieri, I am familiar with Quick Parts, I use them frequently at work. I was thinking about a template with all the paragraphs needed. I want the user to pick only the ones that he uses and after this the document would be stripped of the unused paragraphs. With Quick Parts, it is easy to forget a paragraph and you have to do repetitive tasks (Click insert - Quick Parts for each paragraph) whereas, in my case, it will be faster and the user will have a glympse at all the available options. - Cosmin
I see. Ok, in that case I recommend you to use a userform. I'm not sure how your template looks like. I imagine you could create a template and add bookmarks on the parts the user needs to be able to choose. At template start up you show the userform. In the initialization of this userform you could access all bookmarks and list them in a listbox with style option selection and multi select set to multi. Then you provide a Ok button and there you check which of the boxes are NOT selected and delete the associated bookmarks. - Bruno Bieri
@brunobieri I actually managed to do this with content control check boxes. Basically, every paragraph has a checkbox before. After I check the required paragraphs, I click a submit button and I put a formula to hide all the bookmarks that have the same name as the checkboxes which are not checked. - Cosmin

1 Answers

1
votes

I have managed to do what I intended. First of all, I've put content control checkboxes before every paragraph and I've set a unique tag for each one. Then, for each checkbox, I've selected the paragraph, including the checkbox, and added a bookmark named exactly like the checkbox. Next, I've selected only the checkbox and added a bookmark name hide_nameofthecheckbox.

I've added an ActiveX button, with the following vba Code on click:

Private Sub btnSubmit_Click()
Dim bookmark As String
Dim ctl As ContentControl
    For Each ctl In ActiveDocument.ContentControls
        If ctl.Type = wdContentControlCheckBox Then
            If ctl.Checked = False Then
            bookmark = ctl.Tag
                 Bookmarks(bookmark).Range.Font.Hidden = True
                 Else
                 bookmark = "hide_" & ctl.Tag
                  Bookmarks(bookmark).Range.Font.Hidden = True

                 ' DO NOTHING
            End If
        End If
    Next
End Sub

Basically, when I click the Submit button, the code verifies each checkbox for value True or False. If it is checked, it hides the checkbox, If it is unchecked, it hides the entire paragraph, including the checkbox. This way, after I click the submit button, there will be no checkboxes visible, so the document is print-ready.