'Disable Macros Automatically Microsoft Word Interop

I have a addin in word that on startup tries to use some macros (I presume that's what it's trying to do anyway), and pops up a window that looks similar to

enter image description here

I think the issue is that the addin has an expired digital signature, however, I require this addin to be installed and it can't be updated.

Is there any way to disable the macros, or the addin for this word instance, automatically so that I don't see the popup and my program can run without any user interaction?

So far I've tried disabling alerts, making it not visible, disabling screen update, and setting the automation to force disabled

Application word = new Application()
{
    DisplayAlerts = WdAlertLevel.wdAlertsNone,
    ScreenUpdating = false,
    Visible = false,
    AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable,
};

However, it doesn't seem to work for MS Word 2016 (the version I have to use) as the popup still seems to appear when I run my program.

Note: Whilst I require the addin to be installed and it can't be updated, no addins are required for this program run at all


NuGets for Example:

.NET 6 Console Example:

using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;

Console.WriteLine("Opening Word");

Application word = new Application()
{
    DisplayAlerts = WdAlertLevel.wdAlertsNone,
    ScreenUpdating = false,
    Visible = false,
    AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable,
};

// Popup happens here, prevents execution of remaining code until user has enabled / disabled the macros

Console.WriteLine("Closing Word");

word.Quit();


Solution 1:[1]

When I first read this question, my initial instinct was to see if an instance of Word could be programmatically launched in Safe Mode, which would bypass loading the STARTUP files and displaying the dialog box. However, according to this old MSDN post, once Word is launched in Safe Mode, the Word object model (and any ability to programmatically control Word) is no longer available.

Barring the ability to remediate the digital signature for the file causing the issue, the only other course of action would be to have your application use File.Move to temporarily move the file to a new location, launch Word, and then move the file back to the STARTUP directory after Word has launched.

Possibly complicating this workaround would be the presence of an already running instance of Microsoft Word when you run your application, as attempting to move the file would fail due to it being in use in the other Word instance. If this is a concern, your app would need to detect for the presence of running Word instances and either use an existing instance (without moving the file in STARTUP) or close the existing instances and then launch a new one.

The best approach would be to remediate the file's certificate issue, but since this cannot be done (and the nature of COM-based Word allows no programmatic path to suppressing the dialog box), temporarily moving the file out of the way while Word goes through its launch process seems to be the only avenue to work around this issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 joeschwa