I see that this is an old question, but the post-solution helped me figure it out, and I took it to the next level. It was a little jump. Thanks!
How about converting your function that populates the dictionary with process names and identifiers so that it returns a dictionary object? Then this is a simple task - to fill out a sheet with the contents of the dictionary, which I learned to do from a blog. I wish I had the name of the author, but the link is included.
Sheet1 was assumed of course. Customize as you want. Again, this was a small leap from what you both posted. Absolutely brilliant work guys, thanks!
Sub Test_AllRunningApps() Dim apps As Dictionary Set apps = AllRunningApps() 'Populate a sheet with a dictionary - http://exceldevelopmentplatform.blogspot.com/2018/05/vba-writing-dictionaries-to-worksheet.html Sheet1.Cells(1, 1).Resize(apps.Count, 1).Value2 = Application.Transpose(apps.Keys) Sheet1.Cells(1, 2).Resize(apps.Count, 1).Value2 = Application.Transpose(apps.Items) Set apps = Nothing End Sub 'Similar to: http://msdn.microsoft.com/en-us/library/aa393618%28VS.85%29.aspx Public Function AllRunningApps() As Dictionary Dim strComputer As String Dim objServices As Object, objProcessSet As Object, Process As Object Dim oDic As Object, oDic2 As Object, a() As Variant Set oDic = CreateObject("Scripting.Dictionary") strComputer = "." Set objServices = GetObject("winmgmts:\\" _ & strComputer & "\root\CIMV2") Set objProcessSet = objServices.ExecQuery _ ("Select Name, ProcessID FROM Win32_Process", , 48) For Each Process In objProcessSet If Not oDic.exists(Process.Name) Then oDic.Add Key:=Process.Properties_("Name").Value, Item:=Process.Properties_("ProcessID").Value End If Next Set AllRunningApps = oDic Set objProcessSet = Nothing Set oDic = Nothing End Function
Hopworks
source share