Get list of all open applications

Hello,

I've been trying to create a macro that takes data from an excel sheet and pastes them into an accounting application cell by cell.

In the macro I use AppActivate <windowname> and direct the copy paste commands to the window defined in windowname.

Now, every time I need to send data to a different window, I need to go to the macro and edit the windowname.  Is there some way in excel that I can get a list of all open windows ... no, not workbooks ... I want list of all applications that are open and not hidden.  I can then get that list into a drop down list and select it before the macro goes ahead with the rest of the steps.

So, if someone can help me to:

a) Get a macro to list window names of all running applications in a drop down list and

b) a function to list window names of all running applications so that I can just pick a window name from a cell using data validation,

I would be so happy and grateful :)

Please help as I've been trying to google this for a while now and get all kinds of irrelevant results :(

Oh! I need this for any version of excel 2007 and up.

Thanks for any help,

Cheers :)

I found something that might work for you. Check out this discussion: Names of Currently Running Applications About 2/3s down the page is a link to a spreadsheet by Tim Li. After I downloaded it, saved the .xls to .xlsm and enabled the macros, it gave me a list of open window names.
Author of "OOXML Hacking - Unlocking Microsoft Office's Secrets", ebook now out
John Korchok, Production Manager
production@brandwares.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you John for pointing me to what appears exactly what I am looking for.  Unfortunately, the code seems old and although I save the file as an xlsm file, I get the following error message

at:

________________________________________________________________________________

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _

ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Private Declare Function FindWindow _
    Lib "user32" _
    Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) _
As Long

Private Declare Function AccessibleObjectFromWindow _
    Lib "oleacc" ( _
        ByVal Hwnd As Long, _
        ByVal dwId As Long, _
        riid As tGUID, _
        ppvObject As Object) _
As Long

Private Declare Function AccessibleChildren _
    Lib "oleacc" ( _
        ByVal paccContainer As IAccessible, _
        ByVal iChildStart As Long, _
        ByVal cChildren As Long, _
        rgvarChildren As Variant, _
        pcObtained As Long) _
As Long

________________________________________________________________________________

and the entire portion noted above is coloured red.

Apparently the code does not work on 64 bit systems.  Will it be possible to let me know what the equivalent command is for 64 bit systems?

Thanks,

George

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Is there some way in excel that I can get a list of all open windows ... no, not workbooks ... I want list of all applications that are open and not hidden. 

Use the EnumWindows API to enumerate all windows. Run the code below and look into the immediate window.

Andreas.

Option Explicit

#If Win64 Then
Private Declare PtrSafe Function GetWindowTextLengthA Lib "user32" ( _
    ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
    ByVal hWnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long
#Else
Private Declare Function GetWindowTextLengthA Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
    ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
#End If

Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
#If Win64 Then
Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As Long
#Else
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
    ByVal hWnd As Long, ByVal nIndex As Long) As Long
#End If

#If Win64 Then
Private Declare PtrSafe Function EnumWindows Lib "user32" ( _
    ByVal lpEnumFunc As LongPtr, ByVal lParam As LongPtr) As Long
#Else
Private Declare Function EnumWindows Lib "user32.dll" ( _
    ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
#End If

Sub Main()
  EnumWindows AddressOf EnumFindWindowLikeProc, 0
End Sub

#If Win64 Then
Property Get WindowTitle(ByVal hWnd As LongPtr) As String
#Else
Property Get WindowTitle(ByVal hWnd As Long) As String
#End If
  Dim Contents As String, i As Long
  Contents = Space$(GetWindowTextLengthA(hWnd) + 1)
  i = GetWindowText(hWnd, Contents, Len(Contents))
  WindowTitle = Left$(Contents, i)
End Property

#If Win64 Then
Function IsWindowVisible(ByVal hWnd As LongPtr) As Boolean
#Else
Function IsWindowVisible(ByVal hWnd As Long) As Boolean
#End If
  Const WS_VISIBLE = &H10000000
  Dim lngStyle As Long
  lngStyle = GetWindowLong(hWnd, GWL_STYLE)
  IsWindowVisible = ((lngStyle And WS_VISIBLE) = WS_VISIBLE)
End Function

#If Win64 Then
Private Function EnumFindWindowLikeProc(ByVal hWnd As LongPtr, ByVal lParam As Long) _
    As Long
#Else
Private Function EnumFindWindowLikeProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
#End If
  If IsWindowVisible(hWnd) Then
    Debug.Print WindowTitle(hWnd)
  End If
  EnumFindWindowLikeProc = 1
End Function

3 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated November 22, 2023 Views 1,996 Applies to: