Excel stops working after VBA runs workbook.close on a big file (1.7GB)

Bassie

Board Regular
Joined
Jan 13, 2022
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Hi,

Is this a known problem that VBA stops working on workbook.close if it is trying to close a big file (1.7GB).

My code basically only needs to open the file, copy all the information into a sheet on the workbook with the macro and then close the file. It does everything perfectly but on the workbook.close excel crashes (on smaller workbooks excel doesn't crash)

The code until crash:

VBA Code:
Dim wb, QueryWB As Workbook
Dim MacroWS, Temp As Worksheet
Set wb = ActiveWorkbook
Set MacroWS = Sheets("Macro")

'Let user locate the query output
MsgBox ("Please locate the query output")
Dim FilePath As String
FilePath = Application.GetOpenFilename()
        
        'If user cancels file selection
    If (FilePath) = "False" Then Exit Sub

Workbooks.Open (FilePath)
Set QueryWB = ActiveWorkbook

Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False

wb.Activate

'Copy data from QueryWB to Macro WB
QueryWB.Activate
Range("A1").CurrentRegion.Copy
wb.Activate
Range("A1").PasteSpecial
QueryWB.Close
^^^^ [B]excel crash[/B]
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You could try clearing the clipboard after the paste and before the close which might clear a bit of memory in case that is the problem
add this line:
VBA Code:
Application.CutCopyMode = False
 
Upvote 1
Solution
Also, if you're going to do A Workbook.Close event with DisplayAlerts = False, you need to specify a Save option. QueryWB.Save
 
Upvote 1
Also, if you're going to do A Workbook.Close event with DisplayAlerts = False, you need to specify a Save option. QueryWB.Save
At least this worked for me when I had an Application freeze with one of my Subs
 
Upvote 0
You could try clearing the clipboard after the paste and before the close which might clear a bit of memory in case that is the problem
add this line:
VBA Code:
Application.CutCopyMode = False
Thanks that fixed it !
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top