How to create mutually exclusive radio buttons in word without using ActiveX control?
How to create mutually exclusive radio buttons in word without using ActiveX control?
To create a fillable word form, the content controls of Microsoft Word is very useful. Unfortunately the radio button control is missing from current content control toolbox. Here is an example of using Checkbox as the radio button.
Create a table (2 rows, 3 columns)
Insert 5 check boxes @ row 1, column 2, set their tags from opt11 to opt15
Insert 5 check boxes @ row 2, column 2, set their tags from opt21 to opt25
Paste below code snippet into ThisDocument code pane
Option Explicit
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim sOptNo As String
Dim nOptNo As Integer
Dim oCell As Word.Cell
Dim oRng As Word.Range
Dim oCtrl As ContentControl
sOptNo = Replace(ContentControl.Tag, "opt", "")
If sOptNo <> "" Then
nOptNo = CInt(sOptNo)
If nOptNo >= 11 And nOptNo <= 15 Then
Set oCell = ActiveDocument.Tables(1).Cell(1, 2)
ElseIf nOptNo >= 21 And nOptNo <= 25 Then
Set oCell = ActiveDocument.Tables(1).Cell(2, 2)
End If
Set oRng = oCell.Range
For Each oCtrl In oRng.ContentControls
oCtrl.Checked = False
Next oCtrl
ContentControl.Checked = True
End If
End Sub
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
End Sub
To create a fillable word form, the content controls of Microsoft Word is very useful. Unfortunately the radio button control is missing from current content control toolbox. Here is an example of using Checkbox as the radio button.
Create a table (2 rows, 3 columns)
Insert 5 check boxes @ row 1, column 2, set their tags from opt11 to opt15
Insert 5 check boxes @ row 2, column 2, set their tags from opt21 to opt25
Paste below code snippet into ThisDocument code pane
Option Explicit
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim sOptNo As String
Dim nOptNo As Integer
Dim oCell As Word.Cell
Dim oRng As Word.Range
Dim oCtrl As ContentControl
sOptNo = Replace(ContentControl.Tag, "opt", "")
If sOptNo <> "" Then
nOptNo = CInt(sOptNo)
If nOptNo >= 11 And nOptNo <= 15 Then
Set oCell = ActiveDocument.Tables(1).Cell(1, 2)
ElseIf nOptNo >= 21 And nOptNo <= 25 Then
Set oCell = ActiveDocument.Tables(1).Cell(2, 2)
End If
Set oRng = oCell.Range
For Each oCtrl In oRng.ContentControls
oCtrl.Checked = False
Next oCtrl
ContentControl.Checked = True
End If
End Sub
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
End Sub
Comments
Post a Comment