vba 将宏动态插入到新的 Excel 工作簿中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8635231/
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-08 12:20:22  来源:igfitidea点击:

Dynamically insert macro into a new excel workbook

excelexcel-vbavba

提问by elkbullwinkle

How can an existing macro be inserted into a new excel workbook?

如何将现有的宏插入到新的 Excel 工作簿中?

I want to create a new WorkBook(with vba), and then place an existing macro into the new WorkBook.

我想创建一个新的WorkBook(使用vba),然后将现有的宏放入新的工作簿中。

回答by brettdj

The two options that JMax mentioned:

JMax 提到的两个选项:

"hard way"

"hard way"

"easy way"

"easy way"

  • Use your existing workbook with the UserForm as a template to create the new WorkBook
    1. Save the existing workbook as is (to preserve your current file)
    2. Strip out any unwanted sheets
    3. If you need to strip out any code then you are effectively back to the first option as you will need Pearson's Deleting A Module From A Project / Deleting A Procedure From A Module
    4. Save as a new file
  • 使用您现有的工作簿和用户窗体作为模板来创建新的工作簿
    1. 按原样保存现有工作簿(以保留当前文件)
    2. 去除任何不需要的床单
    3. 如果您需要删除任何代码,那么您实际上会回到第一个选项,因为您将需要 Pearson 的从项目中删除模块/从模块中删除过程
    4. 另存为新文件

We would need to see a sample of your workbook to provide further detailed help.

我们需要查看您的工作簿样本以提供更详细的帮助。