Autoscrolling TextBox in Outlook VBA
Posted on 2004-10-25
I seem to be having trouble getting my textbox to autoscroll to the bottom and keep up with text. Basically my textbox is a status window that displays information about current activities happening in the background and I would like it to remain at the bottom at the most current line. I also want a max limit on the number of lines displayed in the window. I have searched and tried many solutions previously posted. Currently I have:
Const MAXCHARS = 10000
Sub Post (strNewText as String)
If Len(strNewTxt) + Len(.Text) > MAXCHARS Then
.Text = Mid$(.Text, InStr(100 + Len(strNewText), .Text, vbCrLf) + 2)
.SelStart = Len(.Text)
.SelText = strNewText
That posts the information I need to the window properly and maintains the limit, but the scrollbar does not update and remain at the bottom of the window. If I click in the textbox it updates and jumps to the bottom. I tried setting focus to the textbox at the end of the post sub and also attempted a form repaint but neither gets the scrollbar to update properly.
Another solution I saw recommended SendMessage to send a scroll message to the scrollbar but when I try to use Form1.hWnd in Outlook vba I get an undeclared member. Is there something I am missing or someway to get this darn textbox to autoscroll?