c# Interop Word "Call was rejected by callee" only when dialogue is open

0

I have a simple c# application, (which helps entering Header/Footer.)

So all works fine, but when any Dialogue (eg. Select Font) in Word ist opened, I can't connect the "ActiveDocument.Name" any more.

private IopW.Application wordApp;
private IopW.Document wordDoc;
...
wordDoc = wordApp.Documents.Open(Datei);
...
try 
{
    if (wordApp != null && wordApp.ActiveDocument != null)
    {
        Console.Write(wordApp.ActiveDocument.name);
             // Works fine, **if no Dialog is opened** in Word.
             // but when any Dialog is opened i get the error: 
             // System.Runtime.InteropServices.COMException: 
             //     "Aufruf wurde durch Aufgerufenen abgelehnt. 
             //     (Ausnahme von HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))"
             // In English: "Call was rejected by callee"
    }
} catch
{
    ...
}

Try/catch does not prevent the error beeing printed.

Remember: wordApp.ActiveDocument != null, but wordApp.ActiveDocument.name is rejected.

So:

  • How can I prevent this error,
  • or determine if any Dialogue is open,
  • or determine, if my next request will rejected.
c#
ms-word
interop
asked on Stack Overflow Jan 22, 2021 by Aquaball • edited Jan 22, 2021 by macropod

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0