mitchman10
New member
- Joined
- Sep 11, 2013
- Messages
- 1
- Programming Experience
- 10+
I have an app that loops through a sql server database table. On each look it
1. Opens excel, several excel worksheets
2. Makes many insertions into excel based on the data
3. Does all kinds of cutting/pasting
4. Saves the results of all that work in a csv file
I found that as I was going to secondary loops that cutting/pasting and all the other internal Excel functions stopped working right. Data from loop#1 was getting pasted in to Loop #2, as an example..
Pure luck, I stumbled into the fact that if after every loop I completely shut down Excel and then reopened it... the problem was gone. So i added the following code to the program starting on loop #2, prior to opening Excel:
xlWorkSheet = Nothing
xlWorkBook = Nothing
xlWorkSheet2 = Nothing
xlWorkBook2 = Nothing
xlWorkSheet3 = Nothing
xlWorkBook3 = Nothing
xlWorkSheet4 = Nothing
xlWorkBook4 = Nothing
xlApp = Nothing
For Each prockiller In System.Diagnostics.Process.GetProcessesByName("EXCEL")
prockiller.Kill()
Next
and this works great.
But now I want to have the call to launch this process come from a timer so I can have several threads running at the same time. The problem is... lets say I ahve 5 thrreads goinjg, my prockiller loop will kill all versions of excel that are open, not just the ones that its particular thread is using.
Was wondering if anyone could think of a solution to this issue?
Thanks
1. Opens excel, several excel worksheets
2. Makes many insertions into excel based on the data
3. Does all kinds of cutting/pasting
4. Saves the results of all that work in a csv file
I found that as I was going to secondary loops that cutting/pasting and all the other internal Excel functions stopped working right. Data from loop#1 was getting pasted in to Loop #2, as an example..
Pure luck, I stumbled into the fact that if after every loop I completely shut down Excel and then reopened it... the problem was gone. So i added the following code to the program starting on loop #2, prior to opening Excel:
xlWorkSheet = Nothing
xlWorkBook = Nothing
xlWorkSheet2 = Nothing
xlWorkBook2 = Nothing
xlWorkSheet3 = Nothing
xlWorkBook3 = Nothing
xlWorkSheet4 = Nothing
xlWorkBook4 = Nothing
xlApp = Nothing
For Each prockiller In System.Diagnostics.Process.GetProcessesByName("EXCEL")
prockiller.Kill()
Next
and this works great.
But now I want to have the call to launch this process come from a timer so I can have several threads running at the same time. The problem is... lets say I ahve 5 thrreads goinjg, my prockiller loop will kill all versions of excel that are open, not just the ones that its particular thread is using.
Was wondering if anyone could think of a solution to this issue?
Thanks