ユーザーフォーム【コード】
Private Sub UserForm_Initialize()
With UserForm1
.Caption = "この中で好きな映画のジャンルは?"
.Width = "190"
.Height = "140"
End With
With ListBox1
.Width = "170"
.Height = "10"
.Top = "5"
.Left = "10"
.ColumnCount = 2
.ColumnWidths = "40;90"
.TextAlign = fmTextAlignCenter
.AddItem ""
.List(.ListCount - 1, 0) = "ジャンル"
.List(.ListCount - 1, 1) = "例"
End With
With ListBox2
.Width = "170"
.Height = "70"
.Top = "20"
.Left = "10"
.ColumnCount = 2
.ColumnWidths = "40;90"
.TextAlign = fmTextAlignCenter
.AddItem ""
.List(.ListCount - 1, 0) = "アクション"
.List(.ListCount - 1, 1) = "ジャッキーチェン等"
.AddItem ""
.List(.ListCount - 1, 0) = "恋愛"
.List(.ListCount - 1, 1) = "花より男子等"
.AddItem ""
.List(.ListCount - 1, 0) = "コメディ"
.List(.ListCount - 1, 1) = "Mr.ビーン等"
.AddItem ""
.List(.ListCount - 1, 0) = "SF"
.List(.ListCount - 1, 1) = "スターウォーズ等"
.AddItem ""
.List(.ListCount - 1, 0) = "ホラー"
.List(.ListCount - 1, 1) = "リング等"
.AddItem ""
.List(.ListCount - 1, 0) = "アニメ"
.List(.ListCount - 1, 1) = "ディズニー等"
End With
With CommandButton1
.Visible = True
.Width = "70"
.Height = "25"
.Top = "90"
.Left = "15"
.Caption = "決定"
End With
With CommandButton2
.Visible = True
.Width = "70"
.Height = "25"
.Top = "90"
.Left = "105"
.Caption = "キャンセル"
End With
End Sub
Private Sub CommandButton1_Click()
If ListBox2.ListIndex = -1 Then
MsgBox "好きなジャンルを選んでください"
Else
ActiveCell.Value = ListBox2.List(ListBox2.ListIndex, 0)
ActiveCell.Offset(0, 1).Value = ListBox2.List(ListBox2.ListIndex, 1)
Unload Me
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Sub Sample()
UserForm1.Show
End Sub