无法以编程方式在Word 2016中加载宏 [英] Not able to load Macro programmatically in word 2016
问题描述
我已将宏复制到以下路径,
" C:\Program Files( x86)\ Microsoft Office \ Office 16 \STARTUP"
之后如果我手动打开任何单词2016文档宏将被加载,但如果我通过c#.net打开它使用word interop的应用程序我无法在文档中加载宏。
请尽快建议我们。
提前致谢..
首先,您只提到了问题的描述。如果您发布代码,对我们会更有帮助。
从您的描述中我可以理解您在打开文档时尝试运行宏。
所以在这里你可能试图运行
AutoExec 宏。
但还有另一种名为 AutoOpen 宏。
in这两种方式都有一些情况下这个宏执行被抑制。
不同情况下的宏行为
下表总结了这两个宏的行为 当启动Word,或者当一个文件是由各种手段打开:动作                 &NBSP ;                       
AutoExec AutoOpen
----------------------------------------- -------------------------------------------------- ------------------
$
- >键入 以空白文档启动Word                    运行          
在命令提示符下不运行以下
:¥
Winword.exe
- >启动Word与所保存的文档通过键入                    &NBSP ;      奔跑                
在命令提示符下运行以下
:¥
Winword.exe C:\< Yourfile> .doc
<登记/>
- >嵌入在OLE容器&NBSP Word文档;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; 不运行 通过在命令键入以下内容运行
提示符:
WinWord.exe /嵌入C:\< Yourfile> .doc <登记/>
- >使用代码来自动Word和开放&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
是否未运行 使用以下
代码运行$
C:\< Yourfile> .doc:
设置oWord = CreateObject(" Word。申请表")$
oWord.Visible = True
oWord.Documents.Open" C:\YourFile.doc"
- >浏览在Internet Explorer&NBSP文档;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;不运行
运行
或WebBrowser控件
参考:
Word
中AutoExec和AutoOpen宏的行为描述
如果您在上面提到的表格中看到第二个最后一点,那么您会发现如果您尝试使用自动化代码打开文档,那么
Autoexec 宏将无法运行。所以解决方案是创建
AutoOpen 宏。
问候
p>
Deepak
Hi,
I have copied the macro in to the below path,
"C:\Program Files (x86)\Microsoft Office\Office16\STARTUP"
After that if i opened any word 2016 document manually the macro is getting loaded,but if i open it through the c# .net application using word interop i'm not able to load macro in the document.
Kindly suggest us asap.
Thanks in advance..
first of all you only mentioned the description of the problem. it is more helpful for us if you post a code.
from your description I can understand that you are trying to run a macro when you open the document.
so here it is possible that you are trying to run AutoExec macro.
but there is another way named AutoOpen macro.
in these both ways there are some situations when this macro execution get suppressed.
Macro Behaviors in Different Situations
The following table summarizes the behavior of these two macros when Word is started, or when a document is opened by various means: Action AutoExec AutoOpen
-------------------------------------------------------------------------------------------------------------
->Start Word with a blank document by typing Runs Does not run
the following at a command prompt:
Winword.exe
->Start Word with a saved document by typing Runs Runs
the following at a command prompt:
Winword.exe C:\<Yourfile>.doc
->Embed a Word document in an OLE container Does not run Runs
by typing the following at a command
prompt:
WinWord.exe /embedding C:\<Yourfile>.doc
->Use code to automate Word and open Does not run Runs
C:\<Yourfile>.doc by using the following
code:
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open "C:\YourFile.doc"
->Browse to the document in Internet Explorer Does not run Runs
or the WebBrowser controlReference:
Description of behaviors of AutoExec and AutoOpen macros in Word
if you see the second last point in above mentioned table then you will find that if you are trying to open the document using automation code then Autoexec Macro will not run. so the solution is to create AutoOpen Macro.
Regards
Deepak
这篇关于无法以编程方式在Word 2016中加载宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!