I've developed a VSTO Add-In. I've created a Ribbon, which makes a search button appearing into MS Word's Add-In tab.
This Search button opens a Window which allows users to Search the Document from Cloud and Open/ Download the Same.
I want to open the document being searched and downloaded from the cloud to be opened into existing MS Word Window.
My Logic is: When selected document is downloaded by user. I'm copying it in the Local Directory and trying to open the same.
Sample Code:
public void OpenDocument(string documentPath, Form form)
{
_searchForm.Close();
_searchForm.Dispose();
Word.Document newDoc = Globals.ThisAddIn.Application.Documents.Open(documentPath);
newDoc.Activate();
}
But, I'm getting following exception.
You cannot close Microsoft Word because a dialog box is open. Click OK, switch to Word, and then close the dialog box.
OpenDocument
is being called from the form, then the form cannot finish/be disposed at this point in time because it's still executing. Also, the error message mentions trying to close the Word application. I don't see any code in the question that relates to that, so exactly where the problem is is unclear... – Cindy Meister