Search code examples
vbaexcelproject

excel vba projects not closing


I'm going through 100s of excel files in VBA, extracting certain data and copying it to a main spreadsheet in a main workbook. I have a VBA script that resides in this main spreadsheet.

I'm trying to get each source workbook to close after I open it and get what I need. It looks something like this:

dim main_wb
dim source_wb
set main_wb = activeworkbook

Loop thru workbook names
  set source_wb = workbooks.open(a_workbook_name)

  do some stuff
  eventually copy a few rows from various sheets into the main wb

  source_wb.close()
  set source_wb = Nothing
End Loop

The problem is that it SEEMS like the system is continuing to keep the file open in the project explorer ... and eventually it runs out of memory or something. All files work fine individually. It's only when I attempt to process them all at once that I have a problem. The workbook "closes()" but the project still exists in the project explorer in the developer window.

How do I tell it to close out a project. I need to be able to, no BS, close the project and go on to the next one for hundreds and potentially thousands of files - automatically, in code, no intervention from user.


Solution

  • try... It works for me in a similar type of program.

    'closes data workbook
    source_wb.Close False