如果您有两个使用VBA打开的Excel应用程序,如何将工作表从一个Excel应用程序(1)转移到另一个(2)?
问题是,程序员使用JavaScript,当您单击将Web数据传输到xl工作簿的按钮时,它会打开一个新的Excel应用程序.
我知道部分代码是:
Workbooks.Add ActiveSheet.Paste ' Once I returned to the original , i.e. excel app(1).
Stewart John.. 5
没有经过测试,但是类似于:
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
请注意,这假定目标表已存在.如果没有,那么创建一个很容易.
没有经过测试,但是类似于:
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
请注意,这假定目标表已存在.如果没有,那么创建一个很容易.