简体   繁体   English

使用C#中的宏创建新的Word文档

[英]Create new Word document with macro in C#

I made an add-in for Word 2010 in visual studio 2010 (C#), which dynamicly adds new buttons to a new ribbon tab (data from sql database). 我在visual studio 2010(C#)中为Word 2010添加了一个插件,它动态地将新按钮添加到新的功能区选项卡(来自sql数据库的数据)。 Now when i click on a button, a new document with a macro needs to be opend. 现在当我点击一个按钮时,需要打开一个带有宏的新文档。 I have the needed macro in a document (.docm), and the path to it is in the database. 我在文档(.docm)中有所需的宏,并且它的路径在数据库中。

How do I create a new document with the macro from another document? 如何使用其他文档中的宏创建新文档?

It's been months since this question has had a formal answer, so for the record, on Apr 5th 2011, bruggesboy spake thusly: 自从这个问题得到正式回答以来已经好几个月了,所以在2011年4月5日的记录中,bruggesboy如此说:

Fixed it, this is the solution: 修复它,这是解决方案:

    //create new document, location = path to template
    Document doc = Globals.ThisAddIn.Application.Documents.Add(location);
    //auto run macro 
    doc.RunAutoMacro(WdAutoMacros.wdAutoOpen);

And behold, there were word documents with macro's running about. 不料,还有一些关于宏观运行的单词文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM