How to stop macros when opening a Word document using OLE Interop?

As the name implies, I have a .NET application that uses interop to open documents in Word. I have installed

app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable

before opening the document. According to the documentation, this "Disables all macros in all files open programmatically, without any security warnings"

However, when I try to open one specific document, a dialog box appears on the screen that says "the object cannot be loaded because it is not available on this computer." This is a client document, but I believe that it contains a macro with links to a COM object that I did not install.

Am I doing something stupid? is there any way to actually disable macros when opening a word document?

+4
source share
1 answer

Try:

WordBasic.DisableAutoMacros 1

In Bizerrely, this depends on returning to the days before VBA, but it still seems to be the most reliable way to ensure that automatic macros will not start (in any document - you may want to rotate it back using the β€œ0” parameter).

I recently had a project in which I had to process 6,000 Word templates (yes, templates, not documents), many of which had things like macros, etc. I was able to process everything except 6 using this technique. (I never figured out what the problem is with them). A.


EDIT: for a discussion of how to call this from C #, see: http://www.dotnet247.com/247reference/msgs/56/281785.aspx

+3
source

All Articles