有人可以帮我解决这个问题:
我在workbook1中有一个宏。我做的是
'打开workbook2.txt
Workbooks.OpenText filename:= _
"workbook2.txt", Origin:=437, StartRow _
:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1)), _
TrailingMinusNumbers:=True
' copy a range
Dim test As Range
Set test= Range("G971:M1000")
'close workbook2
Workbooks("workbook2").Close
'copy test in workbook1
Windows("workbook1.xlsm").Activate
Sheets("Sheet1").Select
Range("B3").Select
Selection.PasteSpecial Paste:=test, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
这会导致运行时错误1004.
有人可以提供帮助。
答案 0 :(得分:2)
您必须先复制范围才能粘贴它。你需要的是
在行test.Copy
之后 Set test= Range("G971:M1000")
还关于Paste:=test
。这是不正确的。
Paste
是一个可选参数,它接受任何这些值。我建议您在PasteSpecial
xlPasteAll
xlPasteAllExceptBorders
xlPasteAllMergingConditionalFormats
xlPasteAllUsingSourceTheme
xlPasteColumnWidths
xlPasteComments
xlPasteFormats
xlPasteFormulas
xlPasteFormulasAndNumberFormats
xlPasteValidation
xlPasteValues
xlPasteValuesAndNumberFormats
使用此
bSource.Sheets("Sheet1").Range("B3").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False