PDA

View Full Version : Loop through active window applications



Jeevie
02-26-2011, 09:17 AM
Hi

Can someone help me with code to loop through active windows applications using VBA.

Thanks in advance.

mdmackillop
02-26-2011, 10:08 AM
Word has a Tasks method. You can call it from Excel as follows. Check it out in Word VBA Help for more information

Sub Test()
Dim wd As Object
Dim t, i as long
Set wd = CreateObject("word.application")
For Each t In wd.Tasks
i = i + 1
Cells(i, 1) = t
Next
wd.Quit
Set wd = Nothing
End Sub

Jeevie
02-26-2011, 10:22 PM
Thanks for your response. The code pulls all the different simultaneous tasks i.e. hidden/visible. What I need is to pull only the windows applications i.e. Browser, Applications.

How do I do this ? What I am trying to achieve is loop through different windows and grab a screenshot and paste them on to word or excel doc.

Thanks

shrivallabha
02-26-2011, 11:17 PM
You should then use API (Application Programming Interface) for such activity.

There will be some examples available on internet. There's a chapter dedicated to such items in Excel VBA books e.g. Excel 2007 VBA: Programmer's Reference.

Kenneth Hobs
02-27-2011, 08:07 AM
Getting the various instances of MSIE is different than getting instances of applications running. You might want to be more specific in what you need.

If you are checking for a specific instance, I wrote a vb.net program that can tell you if it is running. For that program with the specifics see: http://www.wpuniverse.com/vb/showthread.php?s=&threadid=25128

If you do a search for "Select Name From Win32_Process" you can find other examples.