VBA Excel 2010 - 直接从剪贴板粘贴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36619386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Excel 2010 - Paste directly from clipboard
提问by Mr.Burns
I am trying to paste directly from the clipboard into an excel document and have it so it is transposed
我试图直接从剪贴板粘贴到一个 excel 文档中,然后将其转置
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 strPastedoes have the correct data but it bugs out on the .PasteSpecialsaying object required
将strPaste确实有正确的数据,但它的错误了上.PasteSpecial说对象所需
回答by Lubo? Suk
I think you need to specify target where to paste and on it call PasteSpecial method. You cant call pasteSpecialmethod of string as you trying. (because of that error with object required)
我认为您需要指定目标粘贴位置并在其上调用PasteSpecial method. 您无法pasteSpecial在尝试时调用字符串方法。(因为需要对象的那个错误)
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

