Putting a variable value into the Clipboard

G

Greg de Bruin

I have an Excel macro that reads from several cells and builds them into a
variable. I then want to paste the value of the variable into the Clipboard
so it can be pasted into a text box of another application.

I saw an example in Help that used a DataObject and then used the
PutInClipboard method. This method is not available for a text variable.

What do I have to do to get my text variable into a DataObject. I don't
even know what a DataObject is.

Thanks,

Greg
 
P

Peter T

Hi Greg,

' DataObject requires as reference in Tools/References to
' Microsoft Forms 2.0 Object Library
' This is added automatically if a Userform has ever existed
' in the project. So, quick way is to add/remove a Userform.
'

Sub test()
Dim dob As DataObject
Set dob = New DataObject

dob.SetText "abc"
dob.PutInClipboard

' now paste into any application

End Sub

Not sure why you write this -
This method is not available for a text variable

Quite the contrary, the DataObject can ONLY accept text

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top