试了几个地方
有的有些,有的问题很多
1
workbook open时调用
不好用
Private Sub Workbook_Open()
Load UserForm6
UserForm6.Show
Application.OnKey "a", "wb01"
Debug.Print "open"
End Sub
Function wb01()
Windows(ThisWorkbook.Name).Visible = True
Debug.Print "执行wb01"
End Function
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnKey "a", ""
End Sub
2
Private Sub UserForm_Activate()
Debug.Print "33333"
If keyascii = VBA.KeyCodeConstants.vbKeyEscape Then
Windows(ThisWorkbook.Name).Visible = True
Debug.Print "ESC"
Call wb01
Else
Windows(ThisWorkbook.Name).Visible = False
End If
If KeyCode = vbKeyEscape Then
Windows(ThisWorkbook.Name).Visible = True
Debug.Print "ESC"
Call wb01
Else
Windows(ThisWorkbook.Name).Visible = False
End If
Application.OnKey "{ESC}", "wb01"
End Sub
Function wb01()
Windows(ThisWorkbook.Name).Visible = True
Debug.Print "111"
End Function
3 即使form里这么调用事件也不好用
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If keyascii = 96 Then
Debug.Print "0000"
Else
End If
End Sub
3 worksheet 的事件中调用
Private Sub Worksheet_Activate()
Application.OnKey "{esc}", "wb001"
End Sub
Function wb001()
Debug.Print "执行wb001"
End Function
还出现按下 键盘,直接报错,宏无法调用?
4 过程里应该就更不对了吧
一般打开form时,除非设定了,否则无法使用表