从一个工作簿复制到另一个工作簿
问题描述:
这个应该在copyworkbook中抓住一个范围,然后将其粘贴到主控器中:
This should grab a range in the copyworkbooks then paste it to the master:
Sub activateMacro()
Dim masterWKB, copyWKB As Workbook
Set masterWKB = ThisWorkbook
Dim masterWKS, copyWKS As Worksheet
Set masterWKS = Worksheets("Data")
Dim lastLineCopy, lastLineWKB As Long
Dim pasteRange As Range
Dim listofFileNames As Variant
listofFileNames = buildfilenameArray
for i = 0 to Ubound(listofFileNames)
lastLineWKB = masterWKS.Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row + 1
Debug.Print lastLineWKB
Set copyWKB = Workbooks.Open("c:temp\" & listofFileNames(i, 0) & "")
lastLineCopy = copyWKB.Sheets(1).Columns(1).Find("*", , , , xlByColumns, xlPrevious).Row
Debug.Print lastLineCopy
copyWKB.Sheets(1).Range("A15:AG" & lastLineCopy & "").Copy
masterWKB.masterWKS.Range(masterWKS.Cells(lastLineWKB, 1)).PasteSpecial
Next
end sub
I'm erroring out with object doesn't support his property or method at:
masterWKB.masterWKS.Range(masterWKS.Cells(lastLineWKB, 1)).PasteSpecial
不知道为什么。
编辑:
让它与此配合使用,但我想避免使用激活。
Got it to work with this but I wanted to avoid using activate.
masterWKB.Activate
masterWKS.Range("A" & lastLineWKB & "").PasteSpecial
答
错误:
masterWKB.masterWKS.Cells(lastLineWKB, 1).PasteSpecial