Excel - VBA:如何按键“向上”并改变变量的值? [英] Excel - VBA: How to press key "up" and change value of variable?

查看:101
本文介绍了Excel - VBA:如何按键“向上”并改变变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我正在尝试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
结束子



您可以从以下链接获取信息。


Application.SendKeys方法


Application.OnKey方法


问候,


特里


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.

Application.SendKeys Method

Application.OnKey Method

Regards,

Terry


这篇关于Excel - VBA:如何按键“向上”并改变变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆