VBA Code To Copy multiple text strings from buttons for single paste?

JMB16

New Member
Joined
May 29, 2019
Messages
5
What code do I need to use to instruct a VBA form to copy one or several text strings to clipboard at the activation of one button? Essentially I want to compile different text strings then paste in (any other) application with single <ctrl+v>.

I have figured out how to write the code to copy a SINGLE text string to clipboard using a single button click and here is my code:

Sub Button1_Click()


Dim objData As NewMSForms.DataObject
Dim strText

strText = "1st attempt - no contact; left VM"

objData.SetTextstrText
objData.PutInClipboard


End Sub


#noobiequestion

 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Looks like to me your creating the text string not copying it.

You said:

What code do I need to use to instruct a VBA form to
copy
one or several text strings

Do you mean the data is in some cells and you want to copy it?
 
Upvote 0
Thanks, My Answer

To clarify, I want to copy text from a selected OptionButton or a Command Button.
 
Upvote 0
I still do not understand. But I am sure someone else here on this forum will be able to help you.
 
Upvote 0
Imagine a button that says (Hello) and a button that says (Bye). Then another button that says (Copy).

I need to be able to complete any of these sequences:

#1 sequence:
First click (Hello)
then click (Bye)
then click (Copy)
Output from shortcut ctrl+v in (any other application like a notepad): Hello Bye

#2 sequence:
First click (Hello)
then click (Copy)
Output from shortcut ctrl+v in (any other application like a notepad): Hello

#3 sequence:
First click (Bye)
then click (Hello)
then click (Copy)
Output from shortcut ctrl+v in (any other application like a notepad): Bye Hello

Am I more clear there? Thanks again.
 
Upvote 0
I do not Understand why you would want to do things like this:

If you want to copy:

I want a new car

You would need 5 buttons with captions that would be:

I
Want
A
New
Car


Why not enter:
I want a new car in Range("A1") and then copy Range("A1")
 
Upvote 0
Great question.

Reason is I need to copy disparate strings. Goal is not to create sentences. Imagine being required to log different prices of information about single call center client interactions but my primary application I use for this only allows for text entry. Creating a program that allows for me to copy to clipboard several different common topic strings (that are different on each transaction I’m logging) would save time of either just typing out the string or copy pasting back and forth from destination program and excel. My destination program cannot reference A1.
 
Upvote 0
Using Buttons like this I would think will be difficult.

Like how would a script know when to stop and copy the entire data.

And several other things.

Maybe try this suggestion and see if this would work:

With this script enter all the Terms you might want to use in Column(1)

Like this:

In A1 enter: Good
In A2 enter: Morning
In A3 enter: George
In A4 enter: Mary

Now when you double click on Good

Good will now be entered into Range("C1")

Now when you double click on Morning
Morning will be added to Range("C1")

Now When you double Click on "George" George will be added to Range("C1")

And this can go on and on.

Now when ever you double click on Range("C1") the data in Range("C1") will be copied to the Clip Board

And you can paste it where you want using Ctrl V

Now to clear Range("C1") Double Click on Range("D1")

And you will notice When you double click on any value in Column(1) that cell will turn Green.

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified  5/31/2019  2:30:40 PM  EDT
If Target.Column = 1 Then
Cancel = True
Dim ans As String
ans = ans & " " & Target.Value
Cells(1, 3).Value = Cells(1, 3).Value & ans
Target.Interior.ColorIndex = 4
Columns(3).AutoFit
End If
If Target.Address = Range("C1").Address Then Cancel = True: Target.Copy
If Target.Address = Range("D1").Address Then
Range("C1").Value = ""
Columns(1).Interior.ColorIndex = 0
End If
End Sub
 
Upvote 0
My Aswer: thank you very much. That’s precisely what I needed. How do I give you a good rating (in the spirit of rating an Uber driver?)

Thanks again
 
Upvote 0
Glad I was able to help you.
Knowing I helped you is all I need. I like thinking things through and coming up with ideals.

Come back here to Mr. Excel next time you need additional assistance.
My Aswer: thank you very much. That’s precisely what I needed. How do I give you a good rating (in the spirit of rating an Uber driver?)

Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top