Can't Change Clipboard Due to DataObject Error

kencushing

New Member
Joined
Apr 7, 2006
Messages
8
I have some simple code that I found on the web that populates the clipboard with whatever text you specify.

The problem is that VBA for Excel is not recognizing the DataObject data type.

Is there a Reference that I need to add? Or what am I doing wrong? :rolleyes:

The sample code is below.



Sub PutInClip(sTags As String)

Dim doObject As DataObject

Set doObject = New DataObject

doObject.SetText sTags
doObject.PutInClipboard

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Add a reference to the MS Forms 2.0 Object Library.
 

timorrill

Well-known Member
Joined
Sep 20, 2006
Messages
528
I'm not certain about this, but I think a DataObject is used only in the context of a UserForm, which means that this code would have to appear as part of the UserForm.
 

timorrill

Well-known Member
Joined
Sep 20, 2006
Messages
528
My mistake -- please defer to Norie on this one!

A reference to the MS Forms 2.0 Object Library will indeed do the trick.

Norie -- great job!
 

Forum statistics

Threads
1,136,652
Messages
5,677,008
Members
419,668
Latest member
DharmaK

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
Top