Sub PutStringInClipboard()
'Sub routine to put a string in the clipboard
Dim ans As String
Dim ansDataO As DataObject
Set ansDataO = New DataObject
ans = "Some Text"
ansDataO.SetText ans
ansDataO.PutInClipboard
End Sub
The following macro will copy comment text to the cell to the right, if that cell is empty.
Sub ShowCommentsNextCell()
Application.ScreenUpdating = False
Dim commrange As Range
Dim mycell As Range
Dim curwks As Worksheet
Dim ans As String
Dim ansDataO As DataObject
Set ansDataO = New DataObject
Set curwks = ActiveSheet
On Error Resume Next
Set commrange = curwks.Cells _
.SpecialCells(xlCellTypeComments)
On Error GoTo 0
If commrange Is Nothing Then
MsgBox "no comments found"
Exit Sub
End If
For Each mycell In commrange
ans= ans+mycell.Comment.Text 'Getting comment in a range
Next mycell
ansDataO.SetText ans
ansDataO.PutInClipboard 'pass comment string to clipboard
Application.ScreenUpdating = True
End Sub