0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VBA ユーザーフォーム

Last updated at Posted at 2021-10-31

ブック本体の非表示

Option Explicit
Private Sub CommandButton1_Click()
'Window本体の表示・非表示
  
  'メモ
  '---------------------------------
  '全BookのWindow
  'Application.Visible = True
  '---------------------------------
  'ThisWorkbookのWindowのみ
  'Windows(ThisWorkbook.Name).Visible = True
  '---------------------------------


  If Windows(ThisWorkbook.Name).Visible = True Then
    Windows(ThisWorkbook.Name).Visible = False
  Else
    Windows(ThisWorkbook.Name).Visible = True
  End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'[X]ボタン押下時にWindow本体を表示にする
    Windows(ThisWorkbook.Name).Visible = True
 End Sub

コンボボックス / リストボックス

イニシャライズ

Private Sub UserForm_Initialize()

  'UserFormが表示される際に実行
  '処理

End Sub

アイテム追加

'コンボボックス
'①単体追加
UserForm1.ComboBox1.AddItem "aaa"
'②配列追加
Dim cmbList()
cmbList = Array("bbb", "ccc")
UserForm1.ComboBox1.List = cmbList
'③Range範囲追加
UserForm1.ComboBox1.RowSource = Worksheets("Sheet1").Range("A1:A3").Address(External:=True)
'リストボックス
With UserForm1.ListBox1
  .ColumnCount = 2
  .ColumnWidths = "20;80"
  .List = Worksheets("Sheet1").Range("A1:B3").value
End With

アイテム取得

  '値の取り方
  Dim cmbValue As String, listValue As String
  cmbValue = UserForm1.ComboBox1.Text
  listValue = UserForm1.ListBox1.Text
  MsgBox (cmbValue & vbTab & listValue)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?