Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new Word document with macro in C#

Tags:

c#

ms-word

vba

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). 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.

How do I create a new document with the macro from another document?

like image 758
bruggesboy Avatar asked Apr 05 '11 09:04

bruggesboy


People also ask

Can you create a macro enabled Word document?

Click File > Options > Customize Ribbon. Under Choose commands from, click Macros. Click the macro you want. Under Customize the ribbon, click the tab and custom group where you want to add the macro.

How do I create a macro document?

Method 2: Record a macro using keyboard option Step 1: Open the new or an existing Word document. Step 2: Go to the View tab -> Macros and select Record Macro from the drop-down menu. Enter the Name for the macro.


1 Answers

It's been months since this question has had a formal answer, so for the record, on Apr 5th 2011, bruggesboy spake thusly:

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.

like image 176
2 revs, 2 users 57% Avatar answered Sep 30 '22 11:09

2 revs, 2 users 57%