View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default How to paste clipboard into textbox sheet?

You need to set a reference to the Microsoft Forms 2.0 Object Library through
ToolsReferences in the VBE or declare dobj as Object instead.

Example code:

Sub Test()
Dim dobj As DataObject
Dim mydata As String

On Error GoTo ErrHandler
Set dobj = New DataObject
dobj.GetFromClipboard
mydata = dobj.GetText
With ActiveSheet.OLEObjects("TextBox1").Object
.Text = Replace(mydata, vbCrLf, "")
End With
On Error GoTo 0
Exit Sub
ErrHandler:
MsgBox "Clipboard is empty... ", vbExclamation, _
"Paste from Clipboard"
On Error GoTo 0
End Sub

Greg