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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With