将事件侦听器添加到Excel文本框(失焦) [英] Add event listener to Excel Textbox (lose focus)

查看:147
本文介绍了将事件侦听器添加到Excel文本框(失焦)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试使用AfterUpdate()事件和LoseFocus()这样的事件:

 公共Sub Kommentar_AfterUpdate()

MsgBox(Hurray)

End Sub

文本框名为 Kommentar ,位于表格 Radio 之内。另外,代码应该写在哪里?我已经尝试将其放在无线电表的代码表中,并在单独的模块中。



任何提示,提示或答案都表示赞赏!

解决方案

对于嵌入式ActiveX Excel控件 - 在VBA中的工作表移动中添加以下内容。 TextBox1是控件的名称:

  Private Sub TextBox1_LostFocus()


结束Sub

对于userform,请使用以下文本框:Textbox1是您的文本框的名称:

  Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)


End Sub

如果您不想失去焦点从文本框,您可以将Cancel bool设置为True。另外代码放在UserForm中>>右键点击>>查看代码。


I need to fire an sub or a command when a user is done using a text box in Excel.

I have tried using the AfterUpdate() event and the LoseFocus() event like this:

Public Sub Kommentar_AfterUpdate()

MsgBox ("Hurray")

End Sub

The text box is named Kommentar and is inside the sheet Radio. Also, where is the code supposed to be written? i have tried placing it in code sheet for the Radio sheet, and in a separate module.

Any tip, hint or answer is appreciated!

解决方案

For embedded ActiveX Excel control - add the following in the sheet mobile in VBA. TextBox1 is the name of the control:

Private Sub TextBox1_LostFocus()


End Sub

For userform - use the following where Textbox1 is the name of your textbox:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)


End Sub

You can set the Cancel bool to True if you do not want to lose focus from the textbox. In addition the code is placed within the UserForm >> Right Click >> View Code.

这篇关于将事件侦听器添加到Excel文本框(失焦)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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