Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Office Application hangs during document opening on german windows, works on english one

We found a bug in our service that only seems to be existing in a German version of Microsoft Windows. Here's the code:

public Application OpenApplicationWithFile(object filename)
{
    object _missing = System.Reflection.Missing.Value;
    Application objWord = new Application();
    objWord.DisplayAlerts = WdAlertLevel.wdAlertsNone;
    objWord.Application.Visible = false;
    objWord.Documents.Open(ref filename, ref _readOnly, ref _missing, ref _missing, ref _missing,
                                   ref _missing,
                                   ref _missing, ref _missing, ref _missing, ref _missing, ref _isVisible,
                                   ref _missing,
                                   ref _missing, ref _missing,
                                   ref _missing, ref _missing);
    return objWord;
}

The debugger hangs on the Documents.Open() call, and just stays there waiting - without firing any type of exception or error. We have looked in the event log but only found the following:

Das Dokument 'convert1002.doc' verursachte ein Problem, als es zuletzt geöffnet wurde. Möchten Sie mit dem Öffnen fortfahren?

which translates via google translate to:

The document 'convert1002.doc' caused a serious error last time it was opened. Would you like to continue opening it?

So, it would seem that Word just asked the user something, however since it is invisible the user can't exactly click yes or no. Changing the objWord.Application.Visible value to true doesn't change anything - the word process is still invisible. So my question is how to investigate what is the reason for this scenario and how to fix it. Thanks for any input.

like image 713
Rafał Saltarski Avatar asked Dec 11 '25 05:12

Rafał Saltarski


1 Answers

This error can occur in every Language-Version and depending on the Word-Version you use, it may not be easy to prevent hidden dialogs. Which Word-Version do you use?

But first, your parameters are off by one (i think). ReadOnly is the third parameter and thats why _isVisible my not be working.

I tried to set objWord.Application.Visible to true and it worked for me. Maybe something else is wrong too?

One quick solution may be setting OpenAndRepair to true. Its the 13. Parameter, right behind isVisible.

Otherwise have a look at this Link: How To Dismiss a Dialog Box Displayed by an Office Application with Visual Basic.

like image 53
Uwe Avatar answered Dec 13 '25 20:12

Uwe