如何仅使用vba将单个工作表复制到另一个工作簿 [英] How to copy only a single worksheet to another workbook using vba
问题描述
我有1个工作簿(SOURCE)
,其中包含大约20张表格。
我只想复制1张特定的表单到另一个使用Excel VBA的工作簿(TARGET)
I have 1 WorkBook("SOURCE")
that contains around 20 Sheets.
I want to copy only 1 particular sheet to another Workbook("TARGET")
using Excel VBA.
请注意,目标工作簿尚未存在。它应该在运行时创建。
Please note that the "TARGET" Workbook doen't exist yet. It should be created at runtime.
使用的方法 -
1) code> Activeworkbook.SaveAs < ---不起作用这将复制所有的工作表。我只想要具体的表格。
1) Activeworkbook.SaveAs
<--- Doesn't work. This will copy all the sheets. I want only specific sheet.
请回覆这个有价值的评论。
Please reply this with your valuable comments.
谢谢!!
推荐答案
我有1个工作簿(SOURCE)包含大约20张表。我想使用Excel VBA将只有1张特定的表复制到另一个工作簿(TARGET)。请注意,目标工作簿尚未存在。它应该在运行时创建。
I have 1 WorkBook("SOURCE") that contains around 20 Sheets. I want to copy only 1 particular sheet to another Workbook("TARGET") using Excel VBA. Please note that the "TARGET" Workbook doen't exist yet. It should be created at runtime.
另一种方式
Sub Sample()
'~~> Change Sheet1 to the relevant sheet
'~~> This will create a new workbook with the relevant sheet
ThisWorkbook.Sheets("Sheet1").Copy
'~~> Save the new workbook
ActiveWorkbook.SaveAs "C:\Target.xlsx", FileFormat:=51
End Sub
这将自动创建一个名为Target.xlsx的新工作簿,其中包含相关工作表
This will automatically create a new workbook called Target.xlsx with the relevant sheet
这篇关于如何仅使用vba将单个工作表复制到另一个工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!