我似乎找不到返回正在使用的内存或可用内存的VBA命令。 在Excel 2013中有Application.MemoryUsed但是当我在Excel 2016中尝试时,我得到"类型不匹配",无论我使用
dim myVar as variant
myvar = Application.MemoryUsed
或
MsgBox CStr(Application.MemoryUsed)
这可能是一件简单的事情。或?
答案 0 :(得分:5)
我提出问题后不久就找到了答案。
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
感谢Anonimista!