how to read the amount of used or free memory in Excel 2016 VBA

喜欢而已 提交于 2019-12-10 09:23:17

问题


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?


回答1:


I found the answer shortly after I put the question.

found here: https://social.msdn.microsoft.com/Forums/office/en-US/e3aefd82-ec6a-49c7-9fbf-5d57d8ef65ca/check-size-of-excelexe-in-memory?forum=exceldev

   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!



来源:https://stackoverflow.com/questions/47155175/how-to-read-the-amount-of-used-or-free-memory-in-excel-2016-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!