I was needing to add text to the clipboard from an activecell but within a Userform and I did not want to see the flashing lines around the cell after it was added to the clipboard and so I looked around and found the below code located here:
http://www.xtremevbtalk.com/archive/index.php/t-229994.htmlUser defined type not defined:
Dim MyDataObject As DataObject 'user defined type not defined
Set MyDataObject = New DataObject
MyDataObject.SetText worksheetHeader & vbTab & rowHeader & vbTab & ActiveCell.Value & vbTab & "FY05" & vbTab & "MAY"
MyDataObject.PutInClipboard
So I tried this and it worked like a charm. Here is my final code:
Private Sub CommandButton2_Click()
Dim MyDataObject As DataObject 'user defined type not defined
Set MyDataObject = New DataObject
MyDataObject.SetText ActiveCell.Value
MyDataObject.PutInClipboard
Unload Me
End Sub
This was put in a userform.