Checkbox to Input AutoText

Anonymous
2020-05-03T20:56:36+00:00

I want to auto change the heading of document to read "AT1" when check box CH1 is checked and for the heading to change to "AT2" and some text (actual 4 rows in a table) further down document (highlighted in the screen grab) to be hidden when check box CH2 is checked.  Only check box CB1 or check box CB2 can be checked but not both. 

I know this can be done using bookmarks and some VB coding but admittedly I am a novice when it comes to VB so am help would be greatly appreciated.

The document is laid out using a table (if that makes a difference).

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

18 answers

Sort by: Most helpful
  1. Anonymous
    2020-05-05T18:43:06+00:00

    Hi Jay

    Thanks.  I have made the changes (I think) but still not working.  If I understand your comment regarding autotext, basically there's no need for it as I just type the actual text I want to appear directly in the VB code a shown below.  Is this correct?

    See other screen grabs for changes made

    0 comments No comments
  2. Anonymous
    2020-05-05T18:50:22+00:00

    Hi Jay

    I was a bit trigger happy, found the error and resolved and the form is working as I require.  Many thanks for sharing your expertise and assistance with this, its greatly appreciated.

    Thanks again

    David

    0 comments No comments
  3. Anonymous
    2020-05-05T20:16:50+00:00

    Hi Jay

    One last question, is it possible to auto uncheck CH2 when CH1 is checked and vice-versa?

    0 comments No comments
  4. Jay Freedman 206K Reputation points Volunteer Moderator
    2020-05-05T21:38:31+00:00

    That's exactly what's supposed to happen when the bolded lines execute:

        Select Case CC.Tag ' tag of control being exited

            Case "CH1"

                If CC.Checked Then

                    ccCH2.Checked = False

                    ccATnum.Range.Text = "AT1"

                    ActiveDocument.Bookmarks("HIDE").Range.Font.Hidden = False

                Else

                    ccCH2.Checked = True

                    ccATnum.Range.Text = "AT2"

                    ActiveDocument.Bookmarks("HIDE").Range.Font.Hidden = True

                End If

            Case "CH2"

                If CC.Checked Then

                    ccCH1.Checked = False

                    ccATnum.Range.Text = "AT2"

                    ActiveDocument.Bookmarks("HIDE").Range.Font.Hidden = True

                Else

                    ccCH1.Checked = True

                    ccATnum.Range.Text = "AT1"

                    ActiveDocument.Bookmarks("HIDE").Range.Font.Hidden = False

                End If

            'Case "some other control's tag"

                ' other code

            Case Else

                Exit Sub

        End Select

    What may be confusing is that this doesn't happen until the cursor exits the content control (because this is in Document_ContentControlOnExit, which gets started when the cursor is about to exit). So when you click the check box, but before you hit the Tab key or click another control, you'll see either both boxes checked or both boxes unchecked.

    It is possible to make these check boxes respond immediately instead of waiting for the exit. Greg Maxey has an article at https://gregmaxey.com/word_tip_pages/content_control_custom_events.html that shows how to do it. But this is 400-level wizardry, not really for a novice VBA programmer.

    0 comments No comments
  5. Anonymous
    2020-05-08T12:13:33+00:00

    Thanks Jay, hadn't realised that.  Works fine and thanks again.

    On a separate issue, is it possible to perform calculations in a Word Table and to automatically calculate the cell value with conditional formatting applied to the calculation cell? e.g. cell c1 = a1 x b2 and conditional formatting applied to c1 were cell is filled green when c1 value < 5, filled orange when c1 value is within range 5 to 9 and filled red when c1 value is >9.  Cell d1 would return 1 of 3 standard text items depending on the value of cell c1.

    I appreciate this is standard stuff in Excel (of which I already have a working form) but would prefer to recreate in Word for ease of inputting text, formatting and combining multiple forms into a single working form.

    0 comments No comments