CodeItBetter Programming Another VB Programming Blog

How to get the currently Selected Text in Rich Text Box

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'Controls - How to get the currently Selected Text in Rich Text Box

Option Explicit
 
'Add a Command Button, and a Rich Text Box to your form.

Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
Public Const EM_GETSELTEXT = &H43E
 
Private Sub Command1_Click()
    Dim selectedTxt As String
    Dim lRet As Long
    selectedTxt = Space(1000)
    lRet = SendMessageStr(RichTextBox1.hwnd, EM_GETSELTEXT, 0, ByVal selectedTxt)
    Debug.Print "The selected Text: " & selectedTxt
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.