Sub フォーム1() UserForm1.Show ユーザーフォームのShowModalプロパティを「False」に設定すれば モードレスダイアログになり、「True」でモーダルになります。 End Sub --------------------------------------------------------- Sub フォーム2() UserForm1.Show vbModeless End Sub ------------------------------ Sub フォーム2a() UserForm1.Show 0 End Sub --------------------------------------------------------- Sub フォーム3() UserForm1.Show vbModal End Sub ---------------------------- Sub フォーム3a() UserForm1.Show 1 End Sub |
Sub フォーム4() UserForm1.Hide End Sub ----------------------------------------------------------- Sub フォーム4a() Unload UserForm1 End Sub |
ユーザーフォーム コードウインドウ |
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Cancel = True End Sub |
Sub ダイアログ1() UserForm1.Height = 180 UserForm1.Show vbModeless End Sub -------------------------------------------------------------- Sub ダイアログ2() UserForm1.Height = 321 End Sub |
Dim cnt As Integer 'プロシージャ実行回数 Dim cend1 As String '実行終了数 Dim lblwidth As Integer 'ラベルの幅 Dim ja As Integer Sub ラベル() cend1 = 30 '実行回数 UserForm1.Show 0 For cnt = 1 To cend1 Call プログレス demmyMacro Next UserForm1.Hide End Sub ------------------------------------------------------- Sub demmyMacro() For j = 2 To 10 Cells(2, j) = Int((55 - 1 + 1) * Rnd + 1) Cells(2, j).Interior.ColorIndex = Cells(2, j) For t1 = 1 To 1000 For t2 = 1 To 1000 Next Next Next End Sub ------------------------------------------------------- Sub プログレス() If tsiz = 0 Then With UserForm1 .Caption = "マクロ実行中:しばらくお待ち下さい" .lbl1.BackColor = RGB(0, 153, 255) .lbl1.Width = 0 .lbl2.TextAlign = fmTextAlignCenter .lbl2.BackStyle = 0 .lbl2.Font.Bold = True .lbl2.Font.Size = 14 lblwidth = .lbl2.Width End With End If ja = cnt / cend1 * 100 With UserForm1 .lbl2.Caption = Int(ja) & "%" .lbl1.Width = lblwidth * ja / 100 End With DoEvents End Sub |
※このプログレスは同じサイズの2個のラベルを同じ場所に重ね表示で作ってあります |
Sub ステータスバー例() cend1 = 30 '実行回数 For cnt = 1 To cend1 Call プログレス2(cnt) demmyMacro Next ja = 0 Application.StatusBar = "" End Sub --------------------------------------------------------- Sub プログレス2(i) If (i / cend1) > (cend1 / 10 / cend1 * ja) Then Application.StatusBar = "マクロ実行中" & String(ja + 1, "■") & _ String(10 - ja - 1, "□") ja = ja + 1 End If End Sub |
Sub テキスト1() With UserForm2 .txt1.Text = Date .txt2.Text = "1234" End With UserForm2.Show 0 End Sub |
Sub テキスト2() UserForm2.Show 0 DoEvents With UserForm2 .txt1.Text = "ABCD" .txt3.SetFocus End With End Sub ------------------------------------------------------------ Sub テキスト2a() テキストボックス名を変数で指定 UserForm2.Show 0 For i = 1 To 3 UserForm2("txt" & i).Text = i & i & i & i Next End Sub ------------------------------------------------------------ Sub テキスト2b() テキストボックス名を変数で指定(下記はエラー) UserForm2.Show 0 For i = 1 To 3 UserForm2."txt" & i.Text = i & i & i & i Next End Sub |
Sub テキスト3() With UserForm2 .txt1.Text = "12345678" End With UserForm2.Show 0 With UserForm2 aa = .txt1.Text .txt3.Text = Format(aa, "#,###") End With End Sub |
Sub コンボ1() With UserForm1.cbo1 .RowSource = "コンボボックス" & "!$a$1:$a$9" .ListIndex = 3 End With UserForm1.Show 0 End Sub ---------------------------------------------------------- Sub コンボ2() Dim datcob(9) As String For i = 1 To 9 datcob(i - 1) = Cells(i, 2) Next UserForm1.cbo1.List = datcob UserForm1.Show 0 End Sub |
ユーザーフォーム コードウインドウ |
Private Sub cbo1_Change() Dim ino1 As Integer Dim sdat As String With UserForm1.cbo1 ino1 = .ListIndex If ino1 = -1 Then If .Text = "" Then UserForm1.lbl1 = "選択ボックスの項目を指定して下さい" Exit Sub Else UserForm1.lbl1 = .Text Exit Sub End If End If sdat = .List(ino1) UserForm1.lbl1 = " 項目[" & ino1 + 1 & "]番の【" & sdat & "】を選択" End With End Sub ---------------------------------------------------------- Private Sub CommandButton1_Click() MsgBox "テキストボックスデータ→ " & UserForm1.cbo1.Text Unload UserForm1 End Sub |
Sub リスト1() With UserForm2.lst1 .RowSource = "リスト" & "!$a$1:$a$16" End With UserForm2.Show 0 End Sub ---------------------------------------------------------- Sub リスト2() With UserForm2.lst1 For i = 1 To .ListCount .Selected(i - 1) = False Next End With End Sub |
ユーザーフォーム コードウインドウ |
Private Sub lst1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim lno As Integer Dim ldat As String With UserForm2.lst1 lno = .ListIndex ldat = .List(lno) If InStr(ldat, "◇") > 0 Then Exit Sub End If End With UserForm2.lbl2 = " 項目[" & lno + 1 & "]番の【" & ldat & "】を選択" End Sub |
Sub オプション1() With UserForm3 .opt1.Value = True .Show 0 End With Call オプション1a End Sub -------------------------------------------------------- Sub オプション1a() With UserForm3 If .opt1.Value = True Then UserForm3.lbl1.Caption = "「移動」が選択されました" Else UserForm3.lbl1.Caption = "「コピー」が選択されました" End If End With End Sub |
ユーザーフォーム コードウインドウ |
Private Sub opt1_Change() Call オプション1a End Sub |
Sub チェック1() With UserForm4 .chk1.Value = True .Show 0 End With Call チャック1a End Sub -------------------------------------------------------- Sub チャック1a() Dim msg As String With UserForm4 If .chk1.Value = True Then msg = "「日経平均」" If .chk2.Value = True Then msg = msg & "「TOPIX」" If msg = "" Then UserForm4.lbl2.Caption = "" Else UserForm4.lbl2.Caption = msg & "を表示します" End If End With End Sub |
ユーザーフォーム コードウインドウ |
Private Sub chk1_Change() Call チャック1a End Sub -------------------------------------------------------- Private Sub chk2_Change() Call チャック1a End Sub |
Sub スピン1() With UserForm5 .spn1.Value = 5 .Show 0 End With End Sub |
ユーザーフォーム コードウインドウ |
Private Sub spn1_Change() With UserForm5 .txt1.Text = .spn1.Value End With End Sub ------------------------------------------------------------ Private Sub txt1_Change() If Not IsNumeric(UserForm5.txt1) Then MsgBox "数字を入力して下さい" Exit Sub End If With UserForm5 .spn1.Value = .txt1 End With End Sub |
Dim R As Integer Dim G As Integer Dim B As Integer Sub スクロールバー1() UserForm1.Show End Sub --------------------------------------------------------- Sub スクロールバー1a() Dim R As String, G As String, B As String With UserForm1 R = .scr1.Value G = .scr2.Value B = .scr3.Value .txt2.Text = Hex(R) .txt3.Text = Hex(G) .txt4.Text = Hex(B) UserForm1.txt1.BackColor = RGB(R, G, B) End With End Sub |
ユーザーフォーム コードウインドウ |
Private Sub txt2_Change() ra = txt2.Text On Error Resume Next If "&h" & ra > 255 Then ra = 0 On Error GoTo 0 Else ra = Val("&h" & ra) End If scr1.Value = ra End Sub ・・・・・・・・・・・・ txt3 txt4 ほぼ同上なので省略 ・・・・・・・・・・・・・ -------------------------------------------------------- Private Sub scr1_Change() Call スクロールバー1a End Sub ・・・・・・・・・・・・ txt3 txt4 ほぼ同上なので省略 ・・・・・・・・・・・・・ |
Sub 組み込みダイアログ数() Dim evra As Integer Dim dai As String evra = Val(Application.Version) If evra = 11 Then dai = "Excel2003" If evra = 14 Then dai = "Excel2010" MsgBox "組み込みダイアログ数 → " & _ Application.Dialogs.Count, Title:=dai End Sub |
Dim i As Integer Dim dai As String Sub 組み込みダイアログ1() For i = 1 To 200 On Error Resume Next dai = "" Call 表題 Cells(1, 1).Value = "Dialogs(" & i & ")【" & dai & _ 】を表示中です。「キャンセル」ボタンで次の処理に移ります。 Application.Dialogs(i).Show If Err = 1004 Then Cells(1, 1) = "" On Error GoTo 0 Else kesu = MsgBox("次を表示しますか?", 4, "組み込みダイアログ表示") Cells(1, 1) = "" If kesu = 7 Then Exit For End If End If Next On Error GoTo 0 End Sub --------------------------------------------------------- Sub 表題() For j = 3 To 76 If Cells(j, 1) = i Then dai = Cells(j, 2) Exit For End If Next End Sub |
Sub 組み込みダイアログ2() Dim endr As Integer ThisWorkbook.Sheets("財務指標").Select endr = Range("B1000").End(xlUp).Row Range(Cells(1, 1), Cells(endr, 8)).Select Application.Dialogs(39).Show Range("A1").Select ync = MsgBox("次のマクロ実行は「チャンセル」ボタンを選択", 5, "並べ替え") If ync = 4 Then Call 組み込みダイアログ2 End If →→→→ ここに次に実行するマクロを記述 End Sub |