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

posted @ 2015-06-18 16:04  iluzhiyong  阅读(2863)  评论(0编辑  收藏  举报