将一个 Excel 文件内容复制到另一个 Excel 文件的末尾

发布于 2024-11-27 09:32:19 字数 282 浏览 1 评论 0原文

如何使用 VBA 将一个 Excel 文件复制到另一个 Excel 文件 如何提及两个 Excel 文件的路径?

这是我在互联网上找到的:

ActiveSheet.Move After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)

这是我看到的,但我无法做到,有人可以告诉我如何制作吗?

我必须将一个 Excel 文件的所有行和列复制到另一个 Excel 文件的末尾。
我该怎么做?

How do i copy one excel file to another excel file using VBA How do i mention the paths of the two excel files?

This is what i found on the internet:

ActiveSheet.Move After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)

This is what i saw but im unable to make it can anyone tell me the way i can make it?

I have to copy all the rows and columns of one excel file to the end of the other excel file.
How do I make it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2024-12-04 09:32:19

如果要将工作表从一个工作簿移动(或复制)到另一个工作簿,则必须在变量中设置另一个工作簿。让我举个例子:

Dim oNewWB as Workbook
Dim oCurWB as Workbook
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)

'Move "Sheet1" from the current workbook to new one
oCurWB.Sheets("Sheet1").Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)

[编辑] Maverik 建议的新代码
假设您要将工作簿中的每张工作表复制到新工作簿中:

Dim oNewWB as Workbook
Dim oCurWB as Workbook
Dim Sheet as Worksheet
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)

For Each Sheet In oCurWB.Sheets
  'Move "Sheet1" from the current workbook to new one
  Sheet.Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)
Next Sheet

HTH

If you want to move (or copy) worksheets from a workbook to another, you have to set the other workbook in a var. Let me give you an example:

Dim oNewWB as Workbook
Dim oCurWB as Workbook
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)

'Move "Sheet1" from the current workbook to new one
oCurWB.Sheets("Sheet1").Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)

[EDIT] New piece of code as suggested by Maverik
Let's say you want to copy every sheet in your workbook to the new one:

Dim oNewWB as Workbook
Dim oCurWB as Workbook
Dim Sheet as Worksheet
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)

For Each Sheet In oCurWB.Sheets
  'Move "Sheet1" from the current workbook to new one
  Sheet.Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)
Next Sheet

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文