'EnterキーでEditBox間を移動するサンプルマクロ '新規ブックのモジュールシートに以下のマクロをコピーし 'MakeDialog()、DialogTest1()の順に実行してください。 Option Explicit Dim ObjectGroup As Object Dim ObjectIndex As Integer 'ダイアログフレームに登録するマクロ Sub Form_Load() With ActiveDialog 'エディットボックスのグループを作成 Set ObjectGroup = .DrawingObjects( _ Array("Edit1", "Edit2", "Edit3", "Edit4")) '確認フィールドに初期値を設定 ObjectGroup(ObjectGroup.Count).Text = 1 '現在のオブジェクト番号の初期化 ObjectIndex = 1 '使用可能とフォーカスの設定 ObjectGroup.Enabled = False ObjectGroup(ObjectIndex).Enabled = True .Focus = ObjectGroup(ObjectIndex).Name End With End Sub '標準ボタンに登録するマクロ Sub Next_Click() With ActiveDialog Select Case ObjectIndex '確認フィールドの場合 Case ObjectGroup.Count If ObjectGroup(ObjectGroup.Count).Text = "1" Then .Hide Else ObjectGroup(ObjectGroup.Count).Text = 1 ObjectIndex = 1 End If 'その他のフィールドの場合はオブジェクト番号を増やす Case Is < ObjectGroup.Count ObjectIndex = ObjectIndex + 1 Case Else ObjectIndex = 1 End Select '使用可能とフォーカスの設定 ObjectGroup.Enabled = False ObjectGroup(ObjectIndex).Enabled = True .Focus = ObjectGroup(ObjectIndex).Name End With End Sub 'テストマクロ Sub DialogTest1() With ThisWorkbook.DialogSheets("Dialog1") Do While True .EditBoxes.Text = "" If .Show Then MsgBox .EditBoxes(1).Text & Chr$(10) & _ .EditBoxes(2).Text & Chr$(10) & .EditBoxes(3).Text Else Exit Do End If Loop End With End Sub Sub MakeDialog() Dim dlg As DialogSheet Dim gw As Double Dim i As Integer Set dlg = DialogSheets.Add With dlg .Name = "Dialog1" gw = .Buttons(1).Height / 3 .DialogFrame.Caption = "Test" .DialogFrame.OnAction = "Form_Load" .DrawingObjects.Delete End With For i = 1 To 3 dlg.Labels.Add(Left:=gw * 16, Top:=gw * 7 * i, _ Width:=gw * 19, Height:=gw * 3).Caption = "項目" & i With dlg.EditBoxes.Add(Left:=gw * 16, Top:=gw * (7 * i + 3), _ Width:=gw * 19, Height:=gw * 3) .Name = "Edit" & i .InputType = xlNumber End With Next dlg.Labels.Add(Left:=gw * 16, Top:=gw * 28, _ Width:=gw * 19, Height:=gw * 3).Caption = "確認(OK:1,Cancel:0)" dlg.EditBoxes.Add(Left:=gw * 36, Top:=gw * 28, _ Width:=gw * 5, Height:=gw * 3).Name = "Edit4" With dlg.Buttons.Add(Left:=gw * 52, Top:=gw * 8, _ Width:=gw * 10, Height:=gw * 3) .Caption = StrConv("キャンセル", vbNarrow) .CancelButton = True End With With dlg.Buttons.Add(Left:=gw * 52, Top:=gw * 12, _ Width:=gw * 10, Height:=gw * 3) .OnAction = "Next_Click" .Caption = "次項目" .DefaultButton = True End With End Sub