excel - 如何将多个 Excel 工作表迁移到一个主工作簿
问题描述
我通常有几个带有单独工作表的工作簿来迁移到主工作簿,想想:
- 一月.xlsx
- 二月.xlsx
- 马克斯
- ...
- 十二月.xlsx
回顾一下名为 2020Recap.xlxm 的单张纸。我想构建一个宏来收集每个工作表并写入回顾工作簿,我从下面的 VBA 脚本开始。
我在使用下面的 VBA 时遇到问题
我还想添加到宏中以使用文件名作为工作表名称。
Sub CopySheets()
Workbooks("C:\Test\Account AR Aging Patient.xlsx").Sheets("Account AR Aging Patient.xlsx").Copy _
After:=Workbooks("c:\Test\MEBIllingOffice.xlsm").Sheets(Workbooks("c:\Test\MEBIllingOffice.xlsm").Sheets.Count)
Workbooks("C:\Test\Account AR Aging Payer.xlsx").Sheets("Account AR Aging Payer.xlsx").Copy _
After:=Workbooks("c:\Test\MEBIllingOffice.xlsm").Sheets(Workbooks("c:\Test\MEBIllingOffice.xlsm").Sheets.Count)
Workbooks("C:\Test\AR History.xlsx").Sheets("AR History").Copy _
After:=Workbooks("c:\Test\MEBIllingOffice.xlsm").Sheets(Workbooks("c:\Test\MEBIllingOffice.xlsm").Sheets.Count)
End Sub
解决方案
您在工作表名称中有工作簿名称。尝试:
Dim wb_source As Workbook
Dim wb_target As Workbook
Application.DisplayAlerts = False
Set wb_source = Workbooks.Open("C:\Test\Account AR Aging Patient.xlsx")
Set wb_target = Workbooks.Open("c:\Test\MEBIllingOffice.xlsm")
'assuming the sheet name is "Sheet1"
wb_source.Sheets("Sheet1").Copy after:=wb_target.Sheets(wb_target.Sheets.Count)
wb_source.Close
'next source. note: sheet names must be unique within target
Set wb_source = Workbooks.Open("C:\Test\Account AR Aging Payer.xlsx")
wb_source.Sheets("Sheet2").Copy after:=wb_target.Sheets(wb_target.Sheets.Count)
wb_source.Close
wb_target.Save
wb_target.Close
Application.DisplayAlerts = True
推荐阅读
- html - 从按钮元素中删除边框
- java - 错误:从内部类中访问局部变量 imagesLabel;需要声明为 final (Java)
- uiscrollview - 应用上的 SwiftUI 介绍或教程控制器
- angular - Angular - 更改不同页面上的组件按钮
- python - QTreeView Widget 默认大小占用最大屏幕空间
- typescript - 如何正确缩小包含“对象键或函数”的函数参数
- jquery - chrome 版本 78.0.3904.108(官方版本)(64 位)中 Select 选项列表中的空白问题
- python - 列表的排列
- php - PHP user_registered,可以找到现有用户的日期/时间吗?
- python - 正则表达式在 HTML 中不同的开始和结束字符串之间提取子字符串