Years ago I wrote an application in VB.NET that opens Word documents to make certain corrections to them, and it has been running smoothly until now.
The code is as follows:
Imports Microsoft.Office.Interop.Word
...
Friend WithEvents oWord As Word.Application
Friend WithEvents oWord As Word.Document
Dim varMissing As Object = Type.Missing
...
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Open(Trim(Main.docName.Text), varMissing, varMissing,
varMissing, varMissing, varMissing, varMissing, varMissing,
varMissing, varMissing, varMissing, varMissing, varMissing,
varMissing, varMissing, varMissing)
...
(Of course, I added Microsoft.Office.Interop.Word.dll reference)
Days ago, the version of Word was automatically updated to 16 (previously 15) and from that moment the error occurs:
"You cannot cast the COM object from type Microsoft.Office.Interop.Word.ApplicationClass to the interface type Microsoft.Office.Interop.Word._Application. An operation error occurred because the QueryInterface call on the COM component with IID {00020970-0000-0000-C000-0000000000046} generated the following error: The item was not found. (Exception from HRESULT: 0x002802B (TYPE_E_ELEMENTNOTFOUND))"
in the line of code "oWord.Visible=True".
I have verified in the Task Manager that before the error a "Microsoft Word" task has been created.
Does anyone have any idea why?