How can I get Memory used by Current Excel Application?

M

MikeZz

Hi,
I've been able to find examples of how to pull a list of applications
currently in Task Manager via the functions below. However, I also want to
track memory usage of the currently running Excel Application.

I've looked around and really can't find an example that works. Based on
the examples I've seen (such as those below), this should be pretty easy to
do.

So, if I have xlApp.hwnd, how can I get the current memory being used by it?

Thanks!
MikeZz


Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As
Long
 
S

Steve Yandl

MikeZz,

Here is something you can try.

'-----------------------------------------------

Sub XLmemoryUse()
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'EXCEL.EXE'")
For Each objProcess In colProcessList
MsgBox objProcess.WorkingSetSize / 1024
Next
End Sub


'-----------------------------------------------

Steve Yandl
 
Top