如何在Excel 2016 VBA

时间:2017-11-07 10:10:27

标签: excel-vba excel-2016 vba excel

我似乎找不到返回正在使用的内存或可用内存的VBA命令。 在Excel 2013中有Application.MemoryUsed但是当我在Excel 2016中尝试时,我得到"类型不匹配",无论我使用

    dim myVar      as variant
      myvar = Application.MemoryUsed

    MsgBox CStr(Application.MemoryUsed)

这可能是一件简单的事情。或?

1 个答案:

答案 0 :(得分:5)

我提出问题后不久就找到了答案。

在此处找到: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

感谢Anonimista!