Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copy variable to clipboard

52 views
Skip to first unread message

Greg Glynn

unread,
Jan 7, 2008, 7:33:11 PM1/7/08
to
Is there a better way to copy the contents of a variable into the
clipboard (other than, as below, copy it to a temporary cell)

MyString = "Put this in to the clipboard"
Range("A100") = MyString
Range("A100").Copy
Range("A100").ClearContents

Regards


Greg

Chip Pearson

unread,
Jan 7, 2008, 7:45:10 PM1/7/08
to
The following code will put the text of the active cell into the clipboard.
You'll need a reference to the Forms type library. In VBA, go to the Tools
menu, choose References, and check "Microsoft Forms 2.0 Object Library" (or,
just add a UserForm -- the reference will be automatically added).

Sub CopyToClipboard()
Dim DataObj As New MSForms.DataObject
DataObj.SetText ActiveCell.Text
DataObj.PutInClipboard
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Greg Glynn" <Gregor...@gmail.com> wrote in message
news:3a7f36da-9b42-4c48...@l32g2000hse.googlegroups.com...

itsth...@gmail.com

unread,
Jan 7, 2008, 7:51:00 PM1/7/08
to

Dim mystring As New DataObject


If usf_Convert.tbo_Number_is <> "" Then

number_is.SetText usf_Convert.tbo_Number_is
number_is.PutInClipboard
End If

itsth...@gmail.com

unread,
Jan 7, 2008, 7:55:42 PM1/7/08
to
hit enter by accident while editing some code i had already... anyway

Dim mystring As New DataObject

mystring.SetText "Put In Clipboard"
mystring.PutInClipboard

0 new messages