plungerman
Programmer
- Apr 29, 2013
- 5
I was trying to close Excel from VB 6, or VBA and reopen the same workbook when the routine was run again.
This was made impossible as the Excel process would stay alive (observed on the Task Manager) no matter how much closing
I did.
After trying all the possible answers (thanks, guys!) I had to find my own way (as is always the case
for the true Quest).
I took my block of [Excel Object, Workbook... Closing] code from the bottom of the sub and pasted it to
just below the first creation of the workbook instance, to verify that the object really got wiped out. Then moved this block one step at a time to beneath each reference to cell, sheet, range etc. and verify it was closing then. I would kill the excel process from Task Manager if the code did not, then restart from the Open Excel commands at the top.
Stepping through this way I was able to verify that the Close commands were actually getting rid of the Excel object
right up until they didn't. I was also able to add each close, or = nothing, element to the Close block as it went from the top
through all the code to the bottom. I also started closing in reverse order from opening as reccomended.
This was in fact ridiculous but did indeed nail that pesky range reference responsible for keeping the object open.
This was easily rewritten (don't know why one works but not the other) and the problem was gone.
All threads referring to this issue have been close so I'm the last one to figure it out, but I thought this technique might be of some interest to those still doing battle with this issue.
This was made impossible as the Excel process would stay alive (observed on the Task Manager) no matter how much closing
I did.
After trying all the possible answers (thanks, guys!) I had to find my own way (as is always the case
for the true Quest).
I took my block of [Excel Object, Workbook... Closing] code from the bottom of the sub and pasted it to
just below the first creation of the workbook instance, to verify that the object really got wiped out. Then moved this block one step at a time to beneath each reference to cell, sheet, range etc. and verify it was closing then. I would kill the excel process from Task Manager if the code did not, then restart from the Open Excel commands at the top.
Stepping through this way I was able to verify that the Close commands were actually getting rid of the Excel object
right up until they didn't. I was also able to add each close, or = nothing, element to the Close block as it went from the top
through all the code to the bottom. I also started closing in reverse order from opening as reccomended.
This was in fact ridiculous but did indeed nail that pesky range reference responsible for keeping the object open.
This was easily rewritten (don't know why one works but not the other) and the problem was gone.
All threads referring to this issue have been close so I'm the last one to figure it out, but I thought this technique might be of some interest to those still doing battle with this issue.