Actually now that I think about it (this is air code), this might work.
**** Edit
Nope. It mostly works but if I start frantically clicking on the textbox then the caret moves.
If I behave like a reasonable person then it seems to work ok.
Not a great solution in other words. But I'm leaving it for your judgement.
******
Code:Public Sub SimulateTyping(ByRef Text As String, ByRef Textbox As VB.Textbox, Optional ByRef PauseMS As Long = 150) Dim n As Long Dim s As String dim nStartPos as long ' Adds delay between characters to simulate typing. ' Starts 'typing' wherever the caret is. If Len(Text) = 0 Then Exit Sub With Textbox nStartPos = .Selstart For n = 1 To Len(Text) .Selstart = nStartPos + n ' This *might* put the caret back before typing the next thing in the wrong place? .SelText = Mid$(Text, n, 1) Sleep RollDie(PauseMS) Next n End With End Sub




Reply With Quote