Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

how use vba check

Forum home » Delegate support and help forum » Microsoft Excel Training and help » How to use VBA to check how many excel workbooks are currently o

How to use VBA to check how many excel workbooks are currently o

ResolvedVersion 2016

Anthony has attended:
Excel VBA Intermediate course

How to use VBA to check how many excel workbooks are currently o

I want to find out what VBA codes to program in order to avoid an excel application from crashing due to many excel workbooks being opened by the user.

RE: How to use VBA to check how many excel workbooks are current

Hi Anthony,

Thank you for the forum question and the nice feedback.

I was wrong it is a very complicated task. I remembered it wrong. The FileSystemObject can only return disk space and not memory space.

I found this function which return how much memory Excel use.

Declare Function GetCurrentProcessId Lib "kernel32" () As Long

Function GetMemUsage()

' Returns the current Excel.Application
' memory usage in MB

Set objSWbemServices = GetObject("winmgmts:")
GetMemUsage = objSWbemServices.Get( _
"Win32_Process.Handle='" & _
GetCurrentProcessId & "'").WorkingSetSize / 1024

Set objSWbemServices = Nothing

End Function


The next task is to get Excel to check it every time a new workbook get opened. Unfortunately a Open Workbook event needs to be added to all workbooks to return the space in memory.

I am sorry but this is probably not a good solution.


Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Excel tip:

Move to edge of data block

When data is held in a block, however large, use the Ctrl key with your cursors to move quickly to the far edge of the block. Works with all 4 direction keys.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.16 secs.