Exception from Word.ApplicationClass.Activedocument all of a sudden

前端 未结 4 2067
温柔的废话
温柔的废话 2020-12-11 08:22

I have this single line of code in a Word VSTO add-in project which used to work but suddenly doesn\'t anymore:

Microsoft.Office.Interop.Word.Document doc =          


        
4条回答
  •  醉话见心
    2020-12-11 09:01

    From my experience : when i was closing the Active Document at that time i was refreshing Ribbon Menu according to the active document. If the closing document was the Last document i wasn't able to read any property of

    Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;

    and i was facing the same issue like you.

    whenever i close any document i check

    if(Globals.ThisAddIn.Application.Documents.Count = 1){ 
    LastActiveDocument = true;
    }
    

    And when i refresh the Ribbion Menu i check

    if(!LastActiveDocument){
    // then only read any property of Active document
    }
    

提交回复
热议问题