iliace
Well-known Member
- Joined
- Jan 15, 2008
- Messages
- 3,548
- Office Version
- 365
- 2016
- 2010
- Platform
- Windows
Earlier today, I encountered a very strange glitch that I have not seen before. I won't be able to list all the details of the problem, so I'm hoping if someone has encounted this before could point me in the right direction.
Here is the setup. I have a template that generates a file for each department. There is an external program that populates data into the template file, and then saves it as a new file for each department. However, because the external program does an equivalent of save-as, it uses the same file format as the template file. The template file is an XLSM, and contains the VBA code. The final bit of my code in the template does its own save-as, but saves the file in a XLSX format to get rid of all VBA code, then deletes the original XLSM. It looks something like this:
(I'm leaving out a few details here for simplicity, such as checking for Application.PathSeparator and error handling)
This has been working fine, until I added another part called EventLog. It uses an Excel workbook on a network share to keep track of everything that happens, in a separate module that is periodically called to log the most recent action or error.
So here is the problem
The logging part is working correctly. The code above seems to work as intended - it saves the new file as an XLSX, deletes the XLSM, and closes the workbook. However, within the VBE, in the Project Explorer window, I still see all the different files, the new XLSXs, as if they are still open. There is a VBAProject for each one. Once there are too many, I get an error something like "Excel does not have enough resources to perform the current operation".
I tried the code in debug mode, and here's an interesting twist: none of these "phantom" VBAProjects are accessible. For example, after I have 100 of them open, I use this command in the Immediate window:
and the result is 3, instead of 103 as you might expect. If I try to address any of the by name, like so:
I get an automation error saying the object is not available.
Nonetheless, these phantom VBA projects take up Excel/system resources and eventually cause the process to bum out.
Has anybody encountered a problem of this sort before? If so, please share.
Thanks,
-Ilia
Here is the setup. I have a template that generates a file for each department. There is an external program that populates data into the template file, and then saves it as a new file for each department. However, because the external program does an equivalent of save-as, it uses the same file format as the template file. The template file is an XLSM, and contains the VBA code. The final bit of my code in the template does its own save-as, but saves the file in a XLSX format to get rid of all VBA code, then deletes the original XLSM. It looks something like this:
Code:
Dim p As String
Dim s As String
Dim n As String
p = ThisWorkbook.Path
s = ThisWorkbook.Name
n = Left$(s, InStrRev(s, ".")) & "xlsx"
ThisWorkbook.SaveAs FileName:=p & n, FileFormat:=xlOpenXMLWorkbook
Kill p & s
ThisWorkbook.Close SaveChanges:=False
(I'm leaving out a few details here for simplicity, such as checking for Application.PathSeparator and error handling)
This has been working fine, until I added another part called EventLog. It uses an Excel workbook on a network share to keep track of everything that happens, in a separate module that is periodically called to log the most recent action or error.
So here is the problem
The logging part is working correctly. The code above seems to work as intended - it saves the new file as an XLSX, deletes the XLSM, and closes the workbook. However, within the VBE, in the Project Explorer window, I still see all the different files, the new XLSXs, as if they are still open. There is a VBAProject for each one. Once there are too many, I get an error something like "Excel does not have enough resources to perform the current operation".
I tried the code in debug mode, and here's an interesting twist: none of these "phantom" VBAProjects are accessible. For example, after I have 100 of them open, I use this command in the Immediate window:
Code:
Debug.Print Application.Workbooks.Count
and the result is 3, instead of 103 as you might expect. If I try to address any of the by name, like so:
Code:
Application.Workbooks("PhantomWorkbook42.xlsx").Close SaveChanges:=False
I get an automation error saying the object is not available.
Nonetheless, these phantom VBA projects take up Excel/system resources and eventually cause the process to bum out.
Has anybody encountered a problem of this sort before? If so, please share.
Thanks,
-Ilia