Can't open another Word document NetOffice C#

77 views Asked by At

The conditions are as follows. There is an opened Word document. When I try to open another document in this way:

var application = new Application    // the window appears on this line
{
    Visible = true,
    DisplayAlerts = WdAlertLevel.wdAlertsNone,
}; 
var document = application.Documents.Open(pathToFile);

Microsoft Word Security Notice window pops up:

enter image description here

When I close this window manually, another Word document launches with no problem. I have also tried to add a property:

var application = new Application
{
    Visible = true,
    DisplayAlerts = WdAlertLevel.wdAlertsNone,
    AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable
};

But that didn't help either. I found a post with a similar problem posted 5 years ago: Disable Macros Automatically Microsoft Word Interop.

But I don't need to disable the ability to run macros, I just need to somehow make this window not appear. Or automatically close it. Judging by what I have read, it is almost impossible to do this. But hope dies last :)

P.S. This problem is not present in Excel and PowerPoint for some reason.

1

There are 1 answers

1
Alldman On BEST ANSWER

I was able to deal with this problem in this way:

var application = Application.GetActiveInstance() ??
                new Application    
                {
                    Visible = true,
                    DisplayAlerts = WdAlertLevel.wdAlertsNone,
                }; 
var document = application.Documents.Open(pathToFile);