vba MS Word 2010。如何访问存储在我正在处理的文档以外的文档中的宏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13632795/
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
MS Word 2010. How can I access a macro stored in a document other than the one I am working on?
提问by Freda K
I have written a macro (Foo) in Word VBA that I will use to manipulate data in other Word documents.
I have stored Foo in its own file (MyMacro.docm), not the Normal.dotm file.
I have found that I can't access my macro Foo from the Word datafiles I wish to manipulate (e.g. Datafile.docx), even if 'Macros in all active templates and documents' is selected.
我在 Word VBA 中编写了一个宏 (Foo),我将用它来操作其他 Word 文档中的数据。
我已经将 Foo 存储在它自己的文件 (MyMacro.docm) 中,而不是 Normal.dotm 文件中。
我发现我无法从我希望操作的 Word 数据文件(例如 Datafile.docx)访问我的宏 Foo,即使选择了“所有活动模板和文档中的宏”。
Is it possible to access Foo from Datafile.docx, and if so, which options do I need to change?
是否可以从 Datafile.docx 访问 Foo,如果可以,我需要更改哪些选项?
Thanks, Freda
谢谢,弗雷达
This is what I did to run Foo on the data in the file 'Datafile.docx':
1. Open Word
2. Open MyMacro.docm, enable macros
3. Confirm 'Foo' is available to run from MyMacro.docm - it is
4. Open Datafile.docx
5. Open the list of macros available to run on Datafile.docx - Foo is not available to run on Datafile.docx
6. Press Alt-F11 to access the VBA editor from Datafile.docx - Foo is clearly shown in the modules listed under the MyMacro.docm document.
这就是我对“Datafile.docx”文件中的数据运行 Foo 所做的:
1. 打开 Word
2. 打开 MyMacro.docm,启用宏
3. 确认“Foo”可用于从 MyMacro.docm 运行 - 它是
4. 打开 Datafile.docx
5. 打开可在 Datafile.docx 上运行的宏列表 - Foo 无法在 Datafile.docx 上运行
6. 按 Alt-F11 从 Datafile.docx 访问 VBA 编辑器 - Foo 显然是显示在 MyMacro.docm 文档下列出的模块中。
I tried changing Datafile to a macro-enabled document (Datafile.docm), but it didn't solve the problem.
我尝试将 Datafile 更改为启用宏的文档 (Datafile.docm),但没有解决问题。
回答by rgmatthes
Could you load "MyMacro.docm" as a global template? From Word, click Developer -> Document Template -> Add -> "MyMacro.docm". The macro will be available in the macro list (hit Alt+F8 to view) or from VBA code:
您可以将“MyMacro.docm”加载为全局模板吗?在 Word 中,单击开发人员 -> 文档模板 -> 添加 -> "MyMacro.docm"。宏将在宏列表中可用(按 Alt+F8 查看)或从 VBA 代码中可用:
Application.Run "Foo"