PDA

View Full Version : [SOLVED:] List all Open Window titles in column A



ashleyuk1984
01-04-2014, 08:07 AM
I'm looking for a way of listing all OPEN window application titles in column A.

For instance, if I was to open a new Notepad application, the title would be: "Untitled - Notepad"
The current title of my Chrome browser is: "Excel Help - Post New Thread"
A new Excel document (Maximised) is: "Book1 - Microsoft Excel"

Etc etc.

I've found different variations to this type of question, but it's either to find the 'handle' or to list all the PROCESSES (Which isn't what I want to do)... I want to just list all of the windows titles.

Any ideas?

snb
01-04-2014, 08:49 AM
Sub M_snb()
With CreateObject("Word.application")
ReDim sn(.Tasks.Count, 0)

For j = 1 To .Tasks.Count
sn(j - 1, 0) = .Tasks(j)
Next
End With

cells(1).resize(ubound(sn))=sn
End Sub

ashleyuk1984
01-04-2014, 10:54 AM
Perfect snb thanks!!

ashleyuk1984
03-05-2014, 10:19 AM
Hi snb, or whoever else might be able to help.

I've adapted this code into a loop to perform a long manual process into a automatic overnight process. It works perfectly.
However, there is a small problem.

Each time it loops, it creates a new Word application in the task manager.
The loop is performed up to about 50 times overnight, so it's not an excessive memory hog, but more of an inconvenience for when I arrive into work in the morning.

http://ultraimg.com/images/9gLJt.png

Is there a way of ending the WINWORD.exe task once it's performed it's process task count? Like a 'tidy up' feature if you will.
Thanks

Sorry I've actually just solved this.....

For anyone that's interested, this is how I done it.


Sub M_snb()

Set AppWord = CreateObject("Word.Application")


With AppWord
ReDim sn(.Tasks.Count, 0)

For j = 1 To .Tasks.Count
sn(j - 1, 0) = .Tasks(j)
Next
End With

Cells(1).Resize(UBound(sn)) = sn

AppWord.Quit

End Sub

Thanks anyway.

snb
03-05-2014, 12:38 PM
If you know Word is loaded:

getObject(,"Word.application")



Sub M_snb()
With getObject(,"Word.application")
Redim sn(.Tasks.Count, 0)

For j = 1 To .Tasks.Count
sn(j - 1, 0) = .Tasks(j)
Next
End With

cells(1).resize(UBound(sn))=sn
End Sub

otherwise:


Sub M_snb()
With CreateObject("Word.application")
Redim sn(.Tasks.Count, 0)

For j = 1 To .Tasks.Count
sn(j - 1, 0) = .Tasks(j)
Next
.Quit
End With

cells(1).resize(UBound(sn))=sn
End Sub