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

前端 未结 2 518
情话喂你
情话喂你 2020-12-21 01:49

As the title suggests, I have a .Net application which uses interop to open documents in Word. I have set

app.AutomationSecurity = Microsoft.Office.Core.MsoAut

2条回答
  •  [愿得一人]
    2020-12-21 02:32

    Try:

    WordBasic.DisableAutoMacros 1

    Bizarrely, this relies on a throwback to pre-VBA days, but still seems to be the most-reliable way to ensure that no auto macros are triggered (in any document - you may want to turn it back using the parameter "0").

    I recently had a project where I had to process 6,000 Word templates (yes, templates, not documents) many of which had oddball stuff like macros, etc. I was able to process all but 6 using this technique. (I never did figure out what the problem was with those 6).


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

提交回复
热议问题