基于 VBA 中的模板创建新的 Excel 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9165640/
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
Creating a new Excel File based on a template in VBA
提问by thebiglebowski11
I am building an application in Excel which will enable a user to select from a list of existing excel based tools that have been built. They will select the specific tool and hit a "create new" button. Upon clicking this button, the user will be asked to name the file. After entering the name, a new workbook needs to be created and placed in that specific tool's project folder. I am having trouble implementing this in code. I have been able to find examples of code implementing copying templates from the active workbook, but nothing for creating something that is in another excel file entirely.
我正在 Excel 中构建一个应用程序,该应用程序将使用户能够从已构建的现有基于 excel 的工具列表中进行选择。他们将选择特定工具并点击“新建”按钮。单击此按钮后,将要求用户命名文件。输入名称后,需要创建一个新工作簿并将其放置在该特定工具的项目文件夹中。我无法在代码中实现它。我已经能够从活动工作簿中找到实现复制模板的代码示例,但没有找到完全在另一个 excel 文件中创建内容的示例。
I believe I need to make a copy of the workbook that the user needs to recreate and then change the name and place the file in the desired location.
我相信我需要制作用户需要重新创建的工作簿的副本,然后更改名称并将文件放在所需的位置。
I would post some code to show what I've done so far, but I haven't really made progress.
我会发布一些代码来展示我到目前为止所做的事情,但我还没有真正取得进展。
Thanks,
谢谢,
回答by Patrick Honorez
set wb = workbooks.add("x:\mytemplate.xls")
allows you to create a NEW doc and specify the file to be used as a template.
set wb = workbooks.add("x:\mytemplate.xls")
允许您创建新文档并指定要用作模板的文件。