Excel - VBA:如何按键“向上”并改变变量的值? [英] Excel - VBA: How to press key "up" and change value of variable?
问题描述
嗨!
我正在尝试Excel的工作表(不在UseForm中)按键(向上)或其他类型的键,并更改值一个变量。我想做类似的事情:
Sub hello()
dim a as integer
如果keyUP = 1则
a = 1
如果
则结束
结束子
有可能吗?
谢谢!
嗨Josep ,
Application.SendKeys对按键很有帮助。
看起来像这样。
应用程序。 SendKeys" {Up}"
如果你想按键(向上)时更改值,
您可以在按下键(向上)时自定义事件。
试试这样
Sub AddEvent()
Application.OnKey" ; {Up}"," MyEvent"
End Sub
Sub MyEvent()
Dim A as Integer
A = 1
结束子
您可以从以下链接获取信息。
问候,
特里跨度>
Hi!
I'm trying in a worksheet of Excel (not in a UseForm) to press key (up) or other kind of key, and change the value of one variable. I want to do something like that:
Sub hello()
dim a as integer
If keyUP = 1 then
a = 1
End if
End sub
Is it possible?
Thanks!
Hi Josep,
Application.SendKeys would be helpful for you to press a key.
It looks like this.
Application.SendKeys "{Up}"
If you want to change the value when you press key(Up),
you could customize an event when the key(Up) is pressed.
Try like this
Sub AddEvent() Application.OnKey "{Up}", "MyEvent" End Sub Sub MyEvent() Dim A as Integer A=1 End Sub
You could get information from below links.
Regards,
Terry
这篇关于Excel - VBA:如何按键“向上”并改变变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!