2 回答
TA贡献1788条经验 获得超4个赞
sendkeys 有2个参数的,第2个参数为TRUE,则 Microsoft Excel 等待击键处理完后再将控制返回到宏
那么写成
Application.Quit
Application.SendKeys "{tab}",TRUE
Application.SendKeys "{enter}",TRUE
这样应该行了,MSDN说,向对话框发送按键时,需要先调用SENDKEYS...,我在做试验时,上写的2种方法都可以正常退出..没看出区别,可能是EXCEL版本不一样。
TA贡献1829条经验 获得超6个赞
用API吧
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CommandButton1_Click()
Dim i As Long
keybd_event &H12, 0, 0, 0
For i = 1 To 5
keybd_event &H9, 0, 0, 0
Sleep 1000
keybd_event &H9, 0, &H2, 0
Next
keybd_event &H12, 0, &H2, 0
End Sub
- 2 回答
- 0 关注
- 881 浏览
添加回答
举报