View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Copy variable to clipboard

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" wrote in message
...
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