Roger
asked on
How to automatically paste text to cursor site within text entered into a UserForm textbox?
My user needs to type freehand notes into an Excel UserForm textbox control. But this requires the accurate spelling of some words that are easy to mis-spell, and accuracy is required. So, at the side of the Userform, I can provide the user with a list of these 'tedious' spellings, each in the form of caption text in a UserForm label control.
In the model below, I can replace text in UserForm textbox with new copied text, or I can append new copied text to existing text. But:
MY QUESTION: how do I inset the copied text into existing text at a position marked by the Cursor in the text box?
MY MODEL (attached file):
When the user clicks a label control (in code below ctl.name = "Label1" ) its caption text is copied to clipboard:
Private MyData As New DataObject
Private Sub Label1_Click()
MsgBox "Copy active in Label1_Click()" 'visual check that click event works
MyData.SetText Label1.Caption
MyData.PutInClipboard
End Sub
This pastes copied text into textbox1:
Private Sub pasteText_Click()
TextBox1.Text = MyData.GetText
End Sub
I can append the copied text to existing text in texBox1 by:
TextBox1.Text = TextBox1.Text & " " & MyData.GetText
Thanks
Kelvin4
Paste2TextBox.xlsm
In the model below, I can replace text in UserForm textbox with new copied text, or I can append new copied text to existing text. But:
MY QUESTION: how do I inset the copied text into existing text at a position marked by the Cursor in the text box?
MY MODEL (attached file):
When the user clicks a label control (in code below ctl.name = "Label1" ) its caption text is copied to clipboard:
Private MyData As New DataObject
Private Sub Label1_Click()
MsgBox "Copy active in Label1_Click()" 'visual check that click event works
MyData.SetText Label1.Caption
MyData.PutInClipboard
End Sub
This pastes copied text into textbox1:
Private Sub pasteText_Click()
TextBox1.Text = MyData.GetText
End Sub
I can append the copied text to existing text in texBox1 by:
TextBox1.Text = TextBox1.Text & " " & MyData.GetText
Thanks
Kelvin4
Paste2TextBox.xlsm
ASKER
Yes, but my question (above) is about the positioning of the pasted text at a position marked by the cursor in the text box:
"MY QUESTION: how do I inset the copied text into existing text at a position marked by the Cursor in the text box?"
"MY QUESTION: how do I inset the copied text into existing text at a position marked by the Cursor in the text box?"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, quite correct and very quick response! Kelvin
Private Sub pasteText_Click()
TextBox1.Paste
End Sub