Excel/VBA Project Window mystery
QUESTION: Hi Bob,
Using Excel 2007 VBA
Perhaps you can shed some light on something that strikes me as odd. I have a rather lengthy macro that opens several other excel files, copies data from each, then closes each, as the code runs along.
While I'm running tests, looking at the Project-VBAProject pane in the VBA window, I can watch each file name as it opens and then goes away after the code closes it. Fine and dandy.
The majority appear then disappear as expected. However, there are a couple of file names that remain in the pane well after they have been closed. The code tells them to go away just like the others.
I don't know if this is problem or not, maybe you can explain it.
ANSWER: If you use a statement like
Set x = Something (in the workbook being opened) and you don't say Set x = Nothing then that can happen. Or, if the opened workbooks run code like that, that can happen.
Is that the case?
---------- FOLLOW-UP ----------
QUESTION: There's no code in the opened workbooks. However, there are Set Statements in each portion of the code that deals with the opened workbooks. But only 3 of the dozen or so files do not disappear from the project pane like the others do.
The code works correctly, but I was concerned that maybe they were still "somewhat open" and taking up memory somehow. Not sure if I even need to be concerned about this.
Is Best Practice to "UnSet" after each of sub routines? If so, how do I do it?
If you've done something like
Set x = activeworkbook
then at the end of that sub use
Set x = Nothing.
And yes, it's good practice.
And no, you don't really need to concern yourself with the "phantom" workbooks showing in the VBE -- unlikely to cause a problem. And they disappear when you exit Excel anyway, of course.
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here