Reputation: 350
I can't seem to find a VBA command that returns the memory in use or the memory available. In Excel 2013 there was Application.MemoryUsed but when I try that in Excel 2016 I get "Type mismatch", regardless if I use
dim myVar as variant
myvar = Application.MemoryUsed
or
MsgBox CStr(Application.MemoryUsed)
It's probably a simple thing. Or?
Upvotes: 4
Views: 14342
Reputation: 350
I found the answer shortly after I put the question.
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
Thanks to Anonimista!
Upvotes: 6