-
VBA code to clear all option buttons
I have put a group of option buttons on a form that I am creating in Word. The option buttons are inside a table cell (as are all other form elements i.e. text content controls and drop down list content controls).
I have created the following macro (with the help of many in this forum) that resets and clears all form fields I have so far.
[VBA]Sub ClearFields()
Dim oCC As ContentControl
Dim j As Long
Dim oControls As ContentControls
Dim oLE As ContentControlListEntry
Set oControls = ActiveDocument.ContentControls
For Each oCC In ActiveDocument.Range.ContentControls
If oCC.Type = wdContentControlRichText Then
oCC.Range.Text = " "
End If
Next
For j = 1 To oControls.Count
If oControls(j).Type = wdContentControlDropdownList Then
Set oLE = oControls(j).DropdownListEntries(1)
oLE.Select
End If
Next
End Sub[/VBA]
What I can't figure out is how to code for the clearing of the legacy option buttons. I want to be able to set the form to an entirely clear state with my macro meaning that none of the three option buttons are selected initially.
I appreciate any help.
Thank you,
Brian
-
ActiveX optionbutton controls are an entirely different breed:
Sub ResetRadioButtons()
Dim oILS As InlineShape
Dim oCntr As Object
For Each oILS In ActiveDocument.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If TypeOf oILS.OLEFormat.Object Is MSForms.OptionButton Then
oILS.OLEFormat.Object.Value = False
End If
End If
Next
End Sub
-
I tried this and get a compile error: user-defined type not defined that highlights the following code:
[VBA]TypeOf oILS.OLEFormat.Object Is MSForms.OptionButton[/VBA]
-
In your VB Editor Toos>References. Set a reference to Microsoft Forms 2.0 Object Library.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules