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
How To Deploy Word 2010 Macros To Others?
提问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:
从崇高到荒谬,这里有四种不同的选择:
- Create an add-in. Distribute and tell others to install it. Instructions
- Create a COM add-in. Distribute and tell others to set a reference to it. Instructions
- Export the code module containing your macro to a *.bas file. (Right-click module, Export File...) Distribute and tell others to import it.
- Copy-paste macro code into an e-mail. Distribute and tell others to paste it into a module.
回答by Jed Schaaf
- Go to the VBA Editor.
- Open the Project Explorer if it is not visible (
View>ProjectExplorer
orCtrl+R
). - 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
.
- right click on the project and select
- In the Project Explorer, open Project ( your file)>Modules>ModuleX.
- Copy your code into this module.
- Save the file as a
Word Macro-Enabled Document (*.docm)
(File>Save
orCtrl+S
). - Distribute the file. The code will now go with it.
- 转到 VBA 编辑器。
- 如果项目资源管理器不可见(
View>ProjectExplorer
或Ctrl+R
),请打开它。 - 如果您的文件 (
Project ( _your file_ )
)的项目中需要一个新模块,- 右键单击项目并选择
Insert>Module
- 或 选择项目,然后在菜单上选择
Insert>Module
。
- 右键单击项目并选择
- 在Project Explorer,打开项目(文件)>模块>模块X。
- 将您的代码复制到此模块中。
- 将文件另存为
Word Macro-Enabled Document (*.docm)
(File>Save
或Ctrl+S
)。 - 分发文件。代码现在将随之而来。
回答by JustAC0der
I used an old solution - Nullsoft Scriptable Install Systemto copy the .dotm file to the %Appdata%/Microsoft/word/startup
directory. 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 文件的形式创建了一个小型安装程序,该文件易于分发且易于用户安装。