Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I have a program were I take in data from an excel file and do some basic processing and generate an output file in Excel. The code seems to run ok, but I am not sure if I have a bug.

 

The problem is while the application is running, I cannot open any Excel files (whether or not they are used in the code). Excel itself will load, but the worksheets associated within the file do not. So basically I see the top section (file menu, toolbars, ect) but the space were the worksheets are supposed to be does not load.

 

I saw Gizmo's earlier post and have done the following in my code:

 

This section reads data from excel

Dim Xl As New Excel.Application()
Dim Xlb As Excel.Workbook = Xl.Workbooks.Open(fileName)
Dim Xls As Excel.Worksheet = CType(Xlb.Worksheets(workshtName), Excel.Worksheet)

'search for and collect data by looking for cells with flag set
....

Xlb.Close(False)
Xl.Application.Quit()
Xl = Nothing
Xlb = Nothing
Xls = Nothing

Here is a section of code that writes data to excel

 

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

'Insert data into excel
....

xlSheet.SaveAs(qstExtractFile)
xlBook.Close()
xlApp.Quit()
xlApp = Nothing
xlBook = Nothing
xlSheet = Nothing

 

Is there a bug in my code, or is this the way VB is? I would appreciate it if anyone could shed some light on this.

 

-Thnxs

 

ps. Don't know if this makes any difference, but the program is not multi-threaded and rebooting seems to resolve the issue temorarily. At least until I start the app again.

Edited by cerr
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...