Excel API Error

2

I am using a standardized tool to access the Excel API (software robot). However since upgrading to Office 2013, I am getting an error when I try to open a workbook. The error is this:

Internal : Could not execute code stage because exception thrown by code stage: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))

There is quite a lot of code, and I cannot say for sure which one is failing, but I think it is these 3 lines (edit I have confirmed that it is indeed these lines of code that is failing):

Dim wb as Object = GetInstance(handle).Workbooks.Open(filename)
name = wb.Name
wb.Activate()

I also tried adding some lines on CultureInfo (which didn't help):

Dim wb as Object = GetInstance(handle).Workbooks.Open(filename)
Dim ci As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")

wb.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod, Nothing, wb, Nothing, ci)

name = wb.Name
wb.Activate()

I have researched the error (quite a lot) and found a lot of articles/posts suggestion some regional settings (like this one from Microsoft). I have checked that my Windows is set to English (US), which I also believe is the case for Excel. But I am not sure excactly how to check the language of Excel.

P.S. Can anyone tell me if those 3 lines of code is VBA or VB.NET?

vb.net
excel
ms-office
asked on Stack Overflow May 25, 2016 by Jakob Busk Sørensen • edited May 26, 2016 by Jakob Busk Sørensen

1 Answer

0

After several hours of research (and trial & error), I managed to find a solution. A single line of code was all it took (it's the top line which is new):

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
Dim wb as Object = GetInstance(handle).Workbooks.Open(filename)
name = wb.Name
wb.Activate()

User contributions licensed under CC BY-SA 3.0