Lock Word document after executing a macro with PIA

I am using Office PIA to integrate an application into Word.

There are multiple documents with multiple documents that run a macro when they are opened. My goal is to lock the current document, but after the macro is executed. Is there a way to do this? Thought something like this should work, but there is no event like "MacroExecuted" or whatever:

public void OpenDocument(string path)
{
    var app = new Application();
    app.Documents.Open(path);
    app.ActiveDocument.MacroExecuted += LockDocumentEvent;
    app.Visible = true;
}

      

+3


source to share


1 answer


Found, after a long search:

An important method is contained in the document object.

app.ActiveDocument.RunAutoMacro(WdAutoMacros.wdAutoOpen);

      

The WdAutoMacros enumeration contains various values ​​that indicate which macro should be executed. For me it was



WdAutoMacros.wdAutoNew

and

WdAutoMacros.wdAutoOpen

The macro now runs after opening a document from the Office SDK.

0


source







All Articles