System.InvalidCastException when creating an excel document

  • Thread starter Thread starter NavyIsland
  • Start date Start date
N

NavyIsland

Guest
I am writing an application that reads some data from an AutoCAD DWG file then exports it into an excel spreadsheet. Everything works fine on my dev computer, however, when i run it on a client machine i get a System.InvalidCastException

error message.png

The target framework is .NET 4.6.1, and the target machine has Excel installed as part of the MS Office 365 subscription.

Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value

xlApp = New Excel.Application
Try
xlWorkBook = xlApp.Workbooks.Add(misValue) ' error on this line
Catch ex As Exception
MsgBox(ex.ToString())
MsgBox(ex.InnerException())
RaiseEvent finished()
Exit Sub
End Try

Continue reading...
 

Similar threads

Back
Top