Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to automatically paste text to cursor site within text entered into a UserForm textbox?

Posted on 2014-10-23
4
Medium Priority
?
148 Views
Last Modified: 2014-10-23
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
0
Comment
Question by:Kelvin4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 40399675
You can use:

Private Sub pasteText_Click()
    TextBox1.Paste
End Sub
0
 

Author Comment

by:Kelvin4
ID: 40399694
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?"
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 40399746
This code will paste on the current cursor position
0
 

Author Closing Comment

by:Kelvin4
ID: 40399773
Thanks, quite correct and very quick response! Kelvin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question