Debug.Print所有应用程序名称

时间:2015-07-24 12:33:14

标签: excel excel-vba vba

是否可以列出debug.print中的所有打开的应用程序?

我尝试了以下不起作用的代码。

Dim app As Application
For Each app In Windows.Applications
 Debug.Print app.Name
Next app

1 个答案:

答案 0 :(得分:3)

尝试这样的事情。

Dim strComputer As String
Dim objWMIService As Variant
Dim colItems As Variant
Dim objItem As Variant

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process", , 48)

For Each objItem In colItems
     Debug.Print objItem.ProcessId & " " & objItem.Name & " " & objItem.Caption & " " & objItem.CommandLine  & " " & objItem.ExecutablePath
Next