I'm trying to copy the cell contents into the clipboard.
I've read and tried the exact example provided in the Excel 2007 Help file. However for some reason the DataObject object is not valid. So the example:
Dim MyData As DataObject
Private Sub CommandButton1_Click()
Set MyData = New DataObject
MyData.SetText TextBox1.Text
MyData.PutInClipboard
TextBox2.Paste
End Sub
Private Sub UserForm_Initialize()
TextBox1.Text = "Move this data to a " _
& "DataObject, to the Clipboard, then to " _
& "TextBox2!"
End Sub
Does not work in my case. I've searched for a good while now and I can not find an answer to why the DataObject object is not available.
Here is my code:
Dim MyData As DataObject
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveCell.Column = 3 Then
Set MyData = New DataObject
MyData.SetText ActiveCell.Offset(-1, -1).Text
MyData.PutInclipboard
End If
End Sub
Error on Compile is: "User-Defined type not defined" and it highlights the "MyData As DataObject" line.
Is there another method to simply copying the text in a cell to the clipboard?