本文介绍了VBA Excel 2010-直接从剪贴板粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图直接从剪贴板粘贴到excel文档中,并对其进行转置
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
strPaste
确实具有正确的数据,但会在.PasteSpecial
所说的必需对象上出现错误
The strPaste
does have the correct data but it bugs out on the .PasteSpecial
saying object required
推荐答案
我认为您需要指定目标粘贴位置,并在其上调用PasteSpecial method
.尝试时无法调用string的pasteSpecial
方法. (因为该错误需要对象)
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)
看看这个
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
这篇关于VBA Excel 2010-直接从剪贴板粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!