Thread: Radio buttons.
View Single Post
 
Old 07-21-2020, 02:38 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote