View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Erich Neuwirth Erich Neuwirth is offline
external usenet poster
 
Posts: 41
Default autscrolling textbox on modeless userform

I am using a modeless form with a text box to display
some debugging information while some routines are running.
it works like this:

Sub PrintDebug(Msg As String)
ErrorForm.ErrorTextBox = ErrorForm.ErrorTextBox & _
"Debugging: " & Msg & vbLf
End Sub

I would like the text box to scroll down when it has more text than can
be displayed at once.
With the code above, always the text from the start is displayed.
What do I need to do to make the displayed text
scroll automatically without giving the textbox (or the userform)
focus?


I found some VB code which is supposed to d this in VB, not in VBA.
But I have no idea who I can get the handle of a Textbox
(or of any forms element) in VBA.

Option Explicit

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long
Private Const EM_LINESCROLL = &HB6


Private Sub Command1_Click()

Text1.Text = Text1 & "test" & vbCrLf
PostMessage Text1.hwnd, EM_LINESCROLL, 0&, 2& 'scrolls down 2 lines, or
to bottom.
End Sub
</PRE</CODE