#1
|
|||
|
|||
Radio buttons.
Does anyone have VBA code/macro which will atomically set all radio buttons on a word doc to 'No'? |
#2
|
|||
|
|||
The only type of "radio" buttons that a Word document has is ActiveX optionbuttons. Is that what you are talking about?
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oFld As Field For Each oFld In ThisDocument.Fields Select Case oFld.OLEFormat.ClassType Case Is = "Forms.OptionButton.1" oFld.OLEFormat.Object.Value = False End Select Next lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Hi Greg
Thanks for the reply. Yes the ActiveX option buttons. Basically we have a word doc/questionnaire with basic 'yes', 'no' or 'N/A' answers. Instead of having to click each individual answer to 'no' I was wondering if there was a macro that would enter all the 'no' options. I would believe this could be linked to a command button at the end of document. Do you have any suggestions? Thanks |
#4
|
||||
|
||||
For this type of application, I would use content control list boxes rather than Active X radio buttons. It would then be relatively simple to collate the values, if that is what you wish, at the end. e.g. the following macro will list the various answers. Title the content controls "Answer 1", Answer 2" etc.
I would recommend using https://www.gmayor.com/insert_content_control_addin.htm to insert the first dropdown list control then copy and paste it as often as required, then use the same tool to edit the controls to change the names. Code:
Sub Macro1() Dim oCC As ContentControl Dim i As Integer Dim sYes As String, sNo As String, sNA As String Dim collYes As Collection, CollNo As Collection, CollNA As Collection For Each oCC In ActiveDocument.ContentControls If oCC.ShowingPlaceholderText = True Then oCC.Range.Select MsgBox "Complete " & oCC.TITLE & "!" GoTo lbl_Exit End If Next oCC Set collYes = New Collection Set CollNo = New Collection Set CollNA = New Collection For Each oCC In ActiveDocument.ContentControls If oCC.Type = wdContentControlDropdownList And oCC.TITLE Like "Answer*" Then Select Case UCase(oCC.Range.Text) Case Is = "YES" collYes.Add oCC.TITLE Case Is = "NO" CollNo.Add oCC.TITLE Case Else CollNA.Add oCC.TITLE End Select End If Next oCC For i = 1 To collYes.Count sYes = sYes & collYes.Item(i) If i < collYes.Count Then sYes = sYes & vbCr Next i For i = 1 To CollNo.Count sNo = sNo & CollNo.Item(i) If i < collYes.Count Then sNo = sNo & vbCr Next i For i = 1 To CollNA.Count sNA = sNA & CollNA.Item(i) If i < CollNA.Count Then sNA = sNA & vbCr Next i MsgBox "The following " & collYes.Count & " questions, were answered 'Yes'" & vbCr & sYes & vbCr & vbCr & _ "The following " & CollNo.Count & " questions, were answered 'No'" & vbCr & sNo & vbCr & vbCr & _ "The following " & CollNA.Count & " questions, were answered 'N/A'" & vbCr & sNA lbl_Exit: Set collYes = Nothing Set CollNo = Nothing Set CollNA = Nothing Set oCC = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
If you opt to stick with the ActiveX controls (which I don't recommend) and if the option buttons are in fact captioned "Yes", "No" and "NA" then:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oFld As Field For Each oFld In ThisDocument.Fields Select Case oFld.OLEFormat.ClassType Case Is = "Forms.OptionButton.1" If oFld.OLEFormat.Object.Caption = "No" Then oFld.OLEFormat.Object.Value = True End Select Next lbl_Exit: Exit Sub End Sub |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need help with userform and radio buttons | Fissure | Word VBA | 4 | 04-27-2018 04:10 AM |
Radio Buttons in Word Document in MAC Office 2016 | kim88 | Word | 3 | 12-19-2016 03:36 PM |
check box issue (problem with radio buttons from web page) Word 2013 | cQQlgirl | Word | 6 | 03-19-2015 07:23 PM |
Performance problem ActiveX radio buttons | NobodysPerfect | Word VBA | 8 | 05-31-2014 03:51 AM |
example of radio buttons in for data entry? | derohanes | Excel | 1 | 03-05-2011 09:37 AM |