I am using 32-bit 2013 Excel with VBA extensively. I have disabled hardware graphics acceleration and COM add-ins, yet I still struggle with the following problem:
I am importing the contents of another large workbook with formatting on the cells but with no formulas (~3mb Excel file) into the problematic Excel workbook. On the first attempt - when the contents have not been imported yet - the import succeeds. I am importing the content via VBA similar to the following code:
Application.Workbooks(F_Home).Activate
Workbooks(F_Home).Sheets(Sheet1).Visible = xlSheetVisible
...
Application.Workbooks(F_Source).Activate
Workbooks(F_Source).Sheets(S_Source).Cells.Copy Destination:=Workbooks(F_Home).Sheets(Sheet1).Cells
Application.Workbooks(F_Home).Activate
F_Home is the problematic Excel workbook and F_Source is the workbook with the content we are importing in. When doing this the first time it works, and then I save the file and close out of it, and reopen the file, and try this a second time. On the second time we attempt to import the contents (when the contents already imported) the F_Home workbook crashes with the Out of Memory Error (There isn't enough memory to complete this action...) on the line that copies F_Source contents to F_Home.
Using Process Explorer I've found that the Excel process usually runs around 600mb - 700mb in virtual memory size, but when we run the VBA script to import the contents a second time, the virtual memory size suddenly jumps to 4gb (this does not happen on the first time around, which stays at the 600mb - 700mb range). How should I fix this? I cannot do a workaround such as saving the file before importing the contents a second time, because the timestamp on the file is used and saving the file through VBA will confuse some users.
Thank you for your help.