copy to clipboard

G

greg

This should be easy.
I want to select a cell. then copy the comment from a cell into the
clipboard.

To get the comment I can
Excel.Selection.Comment.Text


for copying to the clipboard. Googline I see a clipboard object. people
use:
Clipboard.setText

but clipboard is not an object for me.
Do you have to add a reference in?
dim it as something?

thanks
 
P

Peter T

If you don't already have a userform, add one and then you can delete it
(just a quick way to add the necessary Reference for DataObject).

Sub ComToClipBrd()
Dim sComText As String
Dim dtaObj As DataObject

On Error Resume Next
sComText = ActiveCell.Comment.Text
On Error GoTo 0

If Len(sComText) Then
Set dtaObj = New DataObject
dtaObj.SetText sComText
dtaObj.PutInClipboard

MsgBox sComText, , "put in clipboard"
End If

End Sub

Regards,
Peter T
 
G

greg

thanks
works great

Peter T said:
If you don't already have a userform, add one and then you can delete it
(just a quick way to add the necessary Reference for DataObject).

Sub ComToClipBrd()
Dim sComText As String
Dim dtaObj As DataObject

On Error Resume Next
sComText = ActiveCell.Comment.Text
On Error GoTo 0

If Len(sComText) Then
Set dtaObj = New DataObject
dtaObj.SetText sComText
dtaObj.PutInClipboard

MsgBox sComText, , "put in clipboard"
End If

End Sub

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top