vba 如何向他人部署 Word 2010 宏?

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

How To Deploy Word 2010 Macros To Others?

vbadeploymentms-wordword-vba

提问by Ann Sanderson

I have a macro that I developed in Word 2010.

我有一个在 Word 2010 中开发的宏。

How do I send this to others to use?

我如何将其发送给其他人使用?

采纳答案by rich tier

Save the document as .dotm (macro enabled template). Save it to

将文档另存为 .dotm(启用宏的模板)。保存到

%Appdata%/Microsoft/word/startup

Close word. Now, it will be accessible to all other word documents.

关闭词。现在,所有其他 Word 文档都可以访问它。

If not by default, then go to templates and tick the file saved above

如果不是默认,则转到模板并勾选上面保存的文件

to deploy, create a simple script that copies the file to the appropriate folder. You can probably deploy via email

要部署,请创建一个简单的脚本,将文件复制到适当的文件夹。您可能可以通过电子邮件进行部署

回答by Jean-Fran?ois Corbett

From the sublime to the ridiculous, here are four different options:

从崇高到荒谬,这里有四种不同的选择:

  1. Create an add-in. Distribute and tell others to install it. Instructions
  2. Create a COM add-in. Distribute and tell others to set a reference to it. Instructions
  3. Export the code module containing your macro to a *.bas file. (Right-click module, Export File...) Distribute and tell others to import it.
  4. Copy-paste macro code into an e-mail. Distribute and tell others to paste it into a module.
  1. 创建加载项。分发并告诉其他人安装它。指示
  2. 创建 COM 加载项。分发并告诉其他人设置对它的引用。指示
  3. 将包含宏的代码模块导出到 *.bas 文件。(右键单击模块,导出文件...)分发并告诉其他人导入它。
  4. 将宏代码复制粘贴到电子邮件中。分发并告诉其他人将其粘贴到模块中。

回答by Jed Schaaf

  1. Go to the VBA Editor.
  2. Open the Project Explorer if it is not visible (View>ProjectExploreror Ctrl+R).
  3. If a new module is needed in the project for your file (Project ( _your file_ )),
    • right click on the project and select Insert>Module
    • OR select the project, then on the menu, select Insert>Module.
  4. In the Project Explorer, open Project ( your file)>Modules>ModuleX.
  5. Copy your code into this module.
  6. Save the file as a Word Macro-Enabled Document (*.docm)(File>Saveor Ctrl+S).
  7. Distribute the file. The code will now go with it.
  1. 转到 VBA 编辑器。
  2. 如果项目资源管理器不可见(View>ProjectExplorerCtrl+R),请打开它。
  3. 如果您的文件 ( Project ( _your file_ ))的项目中需要一个新模块,
    • 右键单击项目并选择 Insert>Module
    • 或 选择项目,然后在菜单上选择Insert>Module
  4. 在Project Explorer,打开项目(文件)>模块>模块X
  5. 将您的代码复制到此模块中。
  6. 将文件另存为Word Macro-Enabled Document (*.docm)(File>SaveCtrl+S)。
  7. 分发文件。代码现在将随之而来。

回答by JustAC0der

I used an old solution - Nullsoft Scriptable Install Systemto copy the .dotm file to the %Appdata%/Microsoft/word/startupdirectory. To do this, I set InstallDir in the NSIS script to this:

我使用了一个旧的解决方案 - Nullsoft Scriptable Install System将 .dotm 文件复制到%Appdata%/Microsoft/word/startup目录中。为此,我将 NSIS 脚本中的 InstallDir 设置为:

InstallDir "$APPDATA\Microsoft\Word\Startup"

NSIS creates a small installer in the form of an EXE file that is easy to distribute and easy for users to install.

NSIS 以 EXE 文件的形式创建了一个小型安装程序,该文件易于分发且易于用户安装。