ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Putting a variable value into the Clipboard (https://www.excelbanter.com/excel-programming/402235-putting-variable-value-into-clipboard.html)

Greg de Bruin

Putting a variable value into the Clipboard
 
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



Peter T

Putting a variable value into the Clipboard
 
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



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





Greg de Bruin

Putting a variable value into the Clipboard
 
Peter,

Thanks very much. You made it easy and now I'm in business.

Greg


"Peter T" <peter_t@discussions wrote in message
...
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



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








All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com