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

问题: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功能相同

转载于:https://www.cnblogs.com/iluzhiyong/p/4586107.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值