MS Word 2007 Forms

MrT82

Board Regular
Joined
Dec 12, 2005
Messages
84
Hello, does anyone know that if in MS Word 2007 you can create a macro that says that if a check box is checked it automatically updates a plain text control box with a value and then locks it for editing please?

Thanks in adv,

Paul
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You can use a 'ContentControlOnExit' macro, in the document's 'ThisDocument' code module, coded like:

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrTxt As String
StrTxt = "Conditional Text"
With ThisDocument
  For i = 1 To .ContentControls.Count
    If ContentControls(i).Title = "Chk1" Then
      If ContentControls(i).Checked = False Then StrTxt = " "
      Exit For
    End If
  Next
  For i = 1 To .ContentControls.Count
    With ContentControls(i)
      If .Title = "Txt1" Then
        .LockContents = False
        .Range.Font.Hidden = False
        .Range.Text = StrTxt
        If StrTxt = " " Then
          .Range.Font.Hidden = True
        End If
        .LockContents = True
        Exit For
      End If
    End With
  Next
End With
End Sub

where your checkbox content control is titled 'Chk1' and your text content control is titled 'Txt1'.
 
Last edited by a moderator:
Upvote 0
Hi Paul,

thanks for your code. Please, next time wrap it in CODE tags so it is easier to read, thank you
Ordinarily, I do. An oversight last time. A more efficient version appears below.
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrTxt As String
StrTxt = "Conditional Text"
With ThisDocument
  If ContentControl.Title = "Chk1" Then
    If ContentControl.Checked = False Then StrTxt = " "
  End If
  For i = 1 To .ContentControls.Count
    With ContentControls(i)
      If .Title = "Txt1" Then
        .LockContents = False
        .Range.Font.Hidden = False
        .Range.Text = StrTxt
        If StrTxt = " " Then .Range.Font.Hidden = True
        .LockContents = True
        Exit For
      End If
    End With
  Next
End With
End Sub
 
Upvote 0
Actually, I've just realised there's a more fundamental issue - unlike Word 2010 & later, Word 2007 doesn't have a checkbox content control. So that raises the question of what kind of checkbox the OP is referring to. In keeping with content control usage, a dropdown content control with, say, Yes/No options could be substituted.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,545
Members
449,317
Latest member
chingiloum

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top