I failed to reference the correct DLL for MS Word.
When I made a reference to Com/
Microsoft.Office.Interop.Word 15.0 object Library 8.6, Visual Studio also made a reference to
Microsoft.Office.Core
.
I used vstudio 2019 community.
Details about my PC
I installed MS Word 2013.
In control panel, one of the programs installed in my PC is
Microsoft Visual Studio 2010 Tools for Office run time(x64).
The PC is 64-bit operating system, x64-based processor.
The error I got is:
Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).
What I have tried:
using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;
....
private void button1_Click_1(object sender, EventArgs e)
{
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
Object name;
Microsoft.Office.Interop.Word.Application wrdApp =
new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wrdDoc =
new Microsoft.Office.Interop.Word.Document();
Object ss = "KeleshaSanad.Docx";
wrdDoc = wrdApp.Documents.Open(ref ss, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
}