您的位置:首页 > 编程语言 > VB

Excel VBA TextBox控件的滚动条不能刷新

2015-06-18 16:04 579 查看
问题:Excel中Textbox控件以及Form里的Textbox控件,当直接填充的内容很长时,滚动条不能实时刷新。

现象:





修改后:





原因:

虽然已经向Textbox的Text里设置了内容,但此时Textbox并没有被激活,焦点也没有变化,所以,Textbox的滚动条没有被刷新出来。

修改后的VBA程序:

-----------------------ActiveX Textbox--------------------------

Private Sub CommandButton1_Click()

TextBox1.Value = "safdasfgsdfgfhfgjhfjfghjfhjfg" _
& Chr(10) _
& "1234567890" _
& Chr(10)

'    IF the text length is long enough, ENABLE the Textbox's scroll bar
TextBox1.Activate
'    Set the current select line: 0
TextBox1.CurLine = 0

End Sub


-----------------------Form Textbox--------------------------

Private Sub CommandButton1_Click()

TextBox1.Value = "safdasfgsdfgfhfgjhfjfghjfhjfg" _
& Chr(10) _
& "1234567890" _
& Chr(10)

'    IF the text length is long enough, ENABLE the Textbox's scroll bar
TextBox1.SetFocus
'    Set the current select line: 0
TextBox1.SelStart = 0

End Sub


知识点:

ActiveX Textbox中的 TextBox1.Activate 和 Form Textbox的 TextBox1.SetFocus功能相同
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: