Hi,
When built for Windows my application can export the contents of a listbox to spreadsheet so that the user can manipulate the results elsewhere.
However, I have a problem that if the user clicks into the spreadsheet at all while it’s getting populated, the export stops and the application crashes. If I’m running in debug mode it still crashes, so doesn’t show me if there is an issue with my code.
I have here some simplified code that still crashes if the user changes anything with the Excel application.
Dim excel As New ExcelApplication
Dim book As ExcelWorkbook
Dim sheet As ExcelWorksheet
dim alphabet() as String = Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
excel.Visible = True
book = excel.Workbooks.Add
dim columnname as String
dim i2, i2total as Integer
dim i, itotal as Integer
i2total = columncount-1
itotal = rowcount-1
excel.ActiveSheet.Name = header
for i = 1 to itotal
for i2 = 1 to i2total
columnname = alphabet(i2-1)
excel.Range(columnname + Str(i), columnname + Str(i)).Value = returncell(i-1, i2-1)
//return cell is a method that returns the text in the cell, I use this because I've written my own listbox to speed things up.
next
next
Exception err as OLEException
MsgBox err.message
How can I get my application to stop crashing when this happens? The code never gets to the OLEException block at the end.
Regards,
Josh