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 Gizmos earlier post and have done the following in my code:
This section reads data from excel
Here is a section of code that writes data to excel
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. Dont 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.
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 Gizmos earlier post and have done the following in my code:
This section reads data from excel
Code:
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
Code:
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. Dont 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.
Last edited by a moderator: