Mr.Burns
Mr.Burns

Reputation: 700

VBA Excel 2010 - Paste directly from clipboard

I am trying to paste directly from the clipboard into an excel document and have it so it is transposed

Dim DataObj As MSForms.DataObject
 Set DataObj = New MSForms.DataObject
 DataObj.GetFromClipboard

strPaste = DataObj.GetText(1)

strPaste.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

The strPaste does have the correct data but it bugs out on the .PasteSpecial saying object required

Upvotes: 1

Views: 28457

Answers (1)

Luboš Suk
Luboš Suk

Reputation: 1546

I think you need to specify target where to paste and on it call PasteSpecial method. You cant call pasteSpecial method of string as you trying. (because of that error with object required)

Take a look at this

Sub testPaste()

    Dim DataObj As MSForms.DataObject
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard

    strPaste = DataObj.GetText(1)

    Sheets("Sheet2").Rows(1).PasteSpecial Transpose:=True

End Sub

Upvotes: 4

Related Questions