如何在Excel工作簿之间复制和粘贴工作表? [英] How to copy and paste worksheets between Excel workbooks?

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

问题描述

如果使用VBA打开两个Excel应用程序,如何将工作表从一个Excel应用程序(1)转移到另一个Excel应用程序(2)?

How do you transfer a worksheet from one excel app(1) to another(2) if you have two excel apps open using VBA?

问题是,程序员使用JavaScript,并且当您单击将Web数据传输到xl工作簿的按钮时,它将打开一个新的Excel应用程序.

The problem is, the programmer uses JavaScript, and when you click on the button that transfers the web data to a xl workbook, it opens a new Excel app.

我知道部分代码将是:

Workbooks.Add
ActiveSheet.Paste    
' Once I returned to the original , i.e. excel app(1).

推荐答案

未经测试,但类似于:

Dim sourceSheet As Worksheet
Dim destSheet As Worksheet

'' copy from the source
Workbooks.Open Filename:="c:\source.xls"
Set sourceSheet = Worksheets("source")
sourceSheet.Activate
sourceSheet.Cells.Select
Selection.Copy

'' paste to the destination
Workbooks.Open Filename:="c:\destination.xls"
Set destSheet = Worksheets("dest")
destSheet.Activate
destSheet.Cells.Select
destSheet.Paste

'' save & close
ActiveWorkbook.Save
ActiveWorkbook.Close

请注意,这假设目标表已经存在.否则,创建一个很容易.

Note that this assumes the destination sheet already exists. It's pretty easy to create one if it doesn't.

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

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