|
すいません、コードの中身が違っていたので訂正します。
【訂正前】
【Sheet1】【Sheet2】の両方
Private Sub CommandButton1_Click()
ChDir ThisWorkbook.Path
Sheet1.Activate
End Sub
【訂正後】
【Sheet1】
Private Sub CommandButton1_Click()
ChDir ThisWorkbook.Path
Sheets("Sheet2").CommandButton1.Activate
End Sub
【Sheet2】
Private Sub CommandButton1_Click()
ChDir ThisWorkbook.Path
Sheets("Sheet1").CommandButton1.Activate
End Sub
【削除】
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
CommandButton1.Activate
End Sub
*********************************************
*********************************************
【ThisWorkbook】
Private Sub Workbook_Open()
ChDir ThisWorkbook.Path
With Application
.ScreenUpdating = False '画面更新なし
.DisplayFormulaBar = False
End With
Sheet1.Activate
End Sub
'エクセルを終了させる。
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Quit
End Sub
【Sheet1】
Private Sub CommandButton1_Click()
ChDir ThisWorkbook.Path
Sheets("Sheet2").CommandButton1.Activate
End Sub
Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Call 移動(KeyCode, 1) 'Tabキー押下でフォーカス移動
If KeyCode = 13 Then 'Enterキー押下でボタンクリック
CommandButton1_Click
End If
End Sub
Private Sub CommandButton2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Call 移動(KeyCode, 2) 'Tabキー押下でフォーカス移動
If KeyCode = 13 Then 'Enterキー押下でボタンクリック
CommandButton1_Click
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
CommandButton1.Activate
End Sub
'Tabキー押下でフォーカス移動をさせるため
Sub 移動(KeyNo, No)
If KeyNo = vbKeyTab Then
If No >= 2 Then
No = 1
Else
No = No + 1
End If
If No = 1 Then
ActiveSheet.OLEObjects("CommandButton1").Activate
ElseIf No = 2 Then
ActiveSheet.OLEObjects("CommandButton2").Activate
End If
End If
End Sub
【Sheet2】
Private Sub CommandButton1_Click()
ChDir ThisWorkbook.Path
Sheets("Sheet1").CommandButton1.Activate
End Sub
Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
CommandButton1_Click
End If
End Sub
'終了ボタン
Private Sub CommandButton2_Click()
ChDir ThisWorkbook.Path
Application.DisplayFormulaBar = True
ActiveWorkbook.Protect Structure:=False, Windows:=True 'ブック
Application.DisplayAlerts = False '確認メッセージを出さない
ActiveWorkbook.Close 'SaveChanges:=False '確認メッセージを出さずに閉じる
Application.DisplayAlerts = True
End Sub
|
|