vba 保存没有宏的 Excel 工作簿的副本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42834527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:18:22  来源:igfitidea点击:

Save a copy of an excel workbook without macro

excelexcel-vbaexcel-2010vba

提问by mbald23

I have an Excel 2010 template file with macros that includes the following code:

我有一个带有宏的 Excel 2010 模板文件,其中包含以下代码:

    ActiveWorkbook.SaveAs Filename:= _
    newname, FileFormat:= _
    51, CreateBackup:=False

This saves the current workbook as a non-Macro enabled workbook, but then I obviously cannot run the rest of the macros that I need.

这会将当前工作簿保存为非启用宏的工作簿,但显然我无法运行我需要的其余宏。

I tried to use

我试着用

    ActiveWorkbook.SaveCopyAs Filename:= _
    newname, FileFormat:= _
    51, CreateBackup:=False

This yields a syntax error. My goal is to save a copy with the new name, so the template file remains unchanged and can be run daily.

这会产生语法错误。我的目标是用新名称保存一个副本,这样模板文件保持不变并且可以每天运行。

采纳答案by Srijan

try this:

尝试这个:

    Dim wMacro As Workbook     'workbook you want to save

    wMacro.Sheets(Array("Sheet1", "Sheet2", "etc")).Select
    wMacro.Sheets(Array("Sheet1", "Sheet2", "etc")).Copy

    ActiveWorkbook.SaveAs Filename:= "filename.xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

it will create a copy and save.

它将创建一个副本并保存。