オプションボタンの使い方:Excel VBA入門 |
スポンサードリンク | |
オプションボタンを配置する | Captionを設定する | オプションボタンの状態を取得する例1 |
オプションボタンの状態を取得する例2 | オプションボタンのグループの設定 | オプションボタンのプロパティ |
Private Sub UserForm_Initialize() OptionButton1.Caption = "20歳未満" OptionButton2.Caption = "20歳以上40歳未満" OptionButton3.Caption = "40歳以上60歳未満" OptionButton4.Caption = "60歳以上" OptionButton1.Value = True End Sub |
Private Sub CommandButton1_Click() Dim myMSG As String If OptionButton1.Value = True Then myMSG = OptionButton1.Caption End If If OptionButton2.Value = True Then myMSG = OptionButton2.Caption End If If OptionButton3.Value = True Then myMSG = OptionButton3.Caption End If If OptionButton4.Value = True Then myMSG = OptionButton4.Caption End If myMSG = myMSG & vbCrLf & "が選択されています" MsgBox myMSG End Sub |
Private Sub CommandButton1_Click() Dim myMSG As String Dim i As Integer For i = 1 To 4 If Me.Controls("OptionButton" & i).Value = True Then myMSG = Me.Controls("OptionButton" & i).Caption End If Next i myMSG = myMSG & vbCrLf & "が選択されています" MsgBox myMSG End Sub |
定数 | 値 | 内容 |
fmAlignmentLeft | 0 | コントロールの左端にキャプションを配置します |
fmAlignmentRight | 1 | (既定値)コントロールの右端にキャプションを配置します |
定数 | 値 | 内容 |
fmBackStyleTransparent | 0 | 背景を透明にします |
fmBackStyleOpaque | 1 | (既定値)背景を不透明にします |
スポンサードリンク
PageViewCounter
Since2006/2/27