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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Add a reference to the MS Forms 2.0 Object Library.
 
Upvote 0
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.
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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
Back
Top