I want to open an Excel file to read some values from it and then close it again. I use the following, simplified code for it.
Dim wbImportFile As Workbook
Dim sFilePath As String
sFilePath = "C:\...\Kundenstamm...xlsx"
'open the workbook read only
Set wbImportFile = Workbooks.Open(sFilePath, ReadOnly:=True)
'Read some values from the open Excel file - nothing very complicated happening here
'...........
'...........
'Close file
wbImportFile.Close False
Set wbImportFile = Nothing
However, after closing the file, it still shows up in the project explorer and each time I run the macro, one more project is added to the project explorer:
I found several similar questions on Stackoverflow, like this one, where Set Workbook = Nothing
did the trick, but I am doing that one already.
The accepted answer in this question did not help me either (specifying SaveAs:=False
).
I have to add that the problem only occures when the VBE is open. If I do not have the code editor open and run the code, no additional projects will appear. However, closing and opening the VBE does not remove the unwanted projects from the project explorer.
Since these projects do not appear when the VBE is closed, I am wondering if this is actually a problem? And if so, what am I doing wrong and can I fix it?