从一个工作簿复制到另一个工作簿 [英] Copy from one workbook to another

查看:173
本文介绍了从一个工作簿复制到另一个工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个应该在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

这篇关于从一个工作簿复制到另一个工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆