Office Interop Exception running Interop v15 on Windows XP

-2

I am running a .exe that i pass an argument to, using Office.Interop v15. It works fine on the dev machine which is windows 7 with Office 2013. When i move to a VM that is running Windows XP and Office 2010, i get a run time error stating

System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

Is it because the interop v15 doesn't support a lower version of office?

Snippet where error occurs

doc = app.Documents.Open(fileToPrint) /happens here
doc.PrintOut(False)
doc.Close()
app.Quit()

Oddly enough it runs but just has a runtime error.

c#
.net
vb.net
winforms
asked on Stack Overflow Apr 9, 2015 by Byrd • edited Apr 10, 2015 by John Saunders

1 Answer

1

Try this.

Replace this code:

doc = app.Documents.Open(fileToPrint) /happens here

With this (in VB.NET)

Dim s_missing As Object = System.Reflection.Missing.Value
doc = app.Documents.Open (fileToPrint, s_missing, s_missing, s_missing, s_missing,s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing, s_missing)

Or with this (in C#)

static object s_missing = System.Reflection.Missing.Value;
doc = app.Documents.Open ( ref fileToPrint,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing,
   ref s_missing );
answered on Stack Overflow Apr 10, 2015 by slayernoah • edited Apr 11, 2015 by slayernoah

User contributions licensed under CC BY-SA 3.0