按下enter键后保持在文本框中 [英] Stay in textbox after enter-key is pressed

查看:121
本文介绍了按下enter键后保持在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在vba(excel)中制作表格。


我使用条形码扫描器来填充文本框。条形码扫描器返回一个值和一个返回/输入。使用on change sub,它会从excel中的tabel中查找信息并填充其他文本框。


输入密钥后可以留在文本框中吗?我试图使用SetFocus,但这不起作用。


我希望有人得到答案。


提前致谢。


解决方案

将文本框的EnterKeyBehavior和Multiline属性设置为True。这意味着当按下Enter时会创建一个新行。如果不想要新行,可以在keyup事件中删除它,例如

 < span style ="color:Blue"> Private   Sub  TextBox1_KeyUp( ByVal  KeyCode  As  MSForms.ReturnInteger, ByVal  
Shift As 整数
如果 KeyCode = vbKeyReturn 那么
TextBox1.Text =替换(TextBox1.Text,vbCrLf,""
结束 如果
结束 Sub

Peter Thornton



Hello,

I am making a form in vba (excel).

I use a barcodescanner to fill a textbox. The barcodescanner returns a value and a return/enter. With an on change sub it looks up information from a tabel in excel and fills other textboxes.

Is is possible to stay in the textbox after the enter-key? I tried to use SetFocus, but that doesn't work.

I hope someone has got an answer.

Thanks in advance.

解决方案

Set both EnterKeyBehavior and Multiline properties of the textbox to True. This means when Enter is pressed a new line is created. If a new line is not wanted it can be removed in the keyup event, eg

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = vbKeyReturn Then
TextBox1.Text = Replace(TextBox1.Text, vbCrLf, "")
End If
End Sub

Peter Thornton


这篇关于按下enter键后保持在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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