在工作簿VBA之间复制和粘贴 [英] Copying and Pasting between Workbooks VBA

查看:590
本文介绍了在工作簿VBA之间复制和粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请忍受,我仍在学习VBA,并且可以在一点帮助下完成。

Please bear with me I am still learning VBA and could do with a little help.

我试图将数据从一个工作簿复制到另一个工作簿,即使在那里已经找到了很多答案,我无法
理解代码,因为它相当复杂。我希望有人可以帮助我编写一个易于阅读和理解的基本代码。

I am trying to copy data from one workbook to another even though there I have found many answers on this I am unable to Understand the code as its quite complicated. I was hoping if someone could help me with a basic code which is pretty easy to read and understand.

我目前正在从3个不同的工作簿中复制所有数据,并将其粘贴到3个工作表中的1个工作簿中。

I am currently looking to copy all data off 3 different workbooks and paste it into 1 workbook across 3 worksheets.

例如,我有3个工作簿,称为

For example I have 3 workbooks called

AA
BB
CC

AA BB CC

我想从这些工作簿中复制所有数据(仅值),然后粘贴到名为

I want to copy all the data (value only) from these workbooks and paste then into workbook called

Main

但是我希望AA。的数据进入Main Worksheet1和
但我希望BB的数据进入Main Worksheet2和
但我希望CC的数据进入Main Worksheet3

But I want that data from AA.to go into Main Worksheet1 and But I want that data from BB to go into Main Worksheet2 and But I want that data from CC to go into Main Worksheet3

我希望我已经正确解释了这个问题,感谢您的帮助。

I hope I have explained this question properly and I appreciate any help.

推荐答案

由于您未提供任何代码,因此足以开始使用。您需要对其进行编辑并进行修复,以适应您的需求。

As you have supplied no code, this should be sufficient enough to get you started. You'll need to edit this and fix this to suite your needs.

Sub test()
    Dim Wb1 As Workbook, Wb2 As WorkBook, Wb3 As Workbook
    Dim MainBook As Workbook

    'Open All workbooks first:
    Set Wb1 = Workbooks.Open(" path to copying book ")
    Set Wb2 = Workbooks.Open(" path to copying book ")
    Set Wb3 = Workbooks.Open(" path to copying book ")
    Set MainBook = Workbooks.Open(" path to destination book ")

    'Now, copy what you want from wb1:
    wb1.Sheets("Sheet1").Cells.Copy
    'Now, paste to Main worksheet:
    MainBook.Sheets("Sheet1").Range("A1").PasteSpecial

    'Now, copy what you want from wb2:
    wb2.Sheets("Sheet1").Cells.Copy
    'Now, paste to Main worksheet:
    MainBook.Sheets("Sheet2").Range("A1").PasteSpecial

    'Now, copy what you want from wb3:
    wb3.Sheets("Sheet1").Cells.Copy
    'Now, paste to Main worksheet:
    MainBook.Sheets("Sheet3").Range("A1").PasteSpecial

    'Close Wb's:
    Wb1.Close
    Wb2.Close
    Wb3.Close
    MainBook.Save
    MainBook.Close

End Sub

这篇关于在工作簿VBA之间复制和粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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