VBA Excel 2010 - Paste directly from clipboard

杀马特。学长 韩版系。学妹 提交于 2020-01-01 19:34:41

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/36619386/vba-excel-2010-paste-directly-from-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!