I have a refernce to the Excel 5.0 library set and see the code below.
I prevously had different versions for this without the Ctype but the reuslt was the same -> eg file is not changed
(code is part of a dblclick event.)
xlBook =... is always the last line the code gets to.
Without the expection handling nothing happens, no error message.
Like this i get follwoing message:
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
A first chance exception of type 'System.NullReferenceException' occurred in MyTest.exe
I'm pretty lost here. In vb6/vba this worked straight forward without any issues.
I also can't set xlapp = New Excel.Application
-> "New can't be used on an interface" message in the code window.
Strange is also that xlBook.Save() and xlApp.Quit() are underlined green in the finally part (but not xlBook.Close()).
-> used before assigned a value
Hope you can help me with this issue.
VB.NET:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlRange As Excel.Range
Try
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlBook = CType(xlApp.Workbooks.Open(FileName), Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
xlRange = CType(xlSheet.Range("A1"), Excel.Range)
xlRange.Value = "Test Value"
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine(ex.InnerException)
Finally
xlBook.Save()
xlBook.Close()
xlApp.Quit()
End Try
I prevously had different versions for this without the Ctype but the reuslt was the same -> eg file is not changed
(code is part of a dblclick event.)
xlBook =... is always the last line the code gets to.
Without the expection handling nothing happens, no error message.
Like this i get follwoing message:
Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
A first chance exception of type 'System.NullReferenceException' occurred in MyTest.exe
I'm pretty lost here. In vb6/vba this worked straight forward without any issues.
I also can't set xlapp = New Excel.Application
-> "New can't be used on an interface" message in the code window.
Strange is also that xlBook.Save() and xlApp.Quit() are underlined green in the finally part (but not xlBook.Close()).
-> used before assigned a value
Hope you can help me with this issue.