Hello Experts, need your assistance in competing the task..
Below code gives list of active windows applications on screen.
however it only provides list.
Assistance - how do we add code which will help us activate the windows application to foreground on double click
Example - I have Word, outlook & notepad open on screen, so once i open macro & run the code it will give me list of the applications & all other applications will be in background..
Notepad
Outlook
Word
Now on double click on Notepad in excel list user should see the Notepad on foreground, it should be activated, maximized & seen on screen.
Private Declare PtrSafe Function apiGetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassname As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function apiGetDesktopWindow Lib "user32" Alias _
"GetDesktopWindow" () As Long
Private Declare PtrSafe Function apiGetWindow Lib "user32" Alias _
"GetWindow" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare PtrSafe Function apiGetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal _
nIndex As Long) As Long
Private Declare PtrSafe Function apiGetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal _
lpString As String, ByVal aint As Long) As Long
Private Const mcGWCHILD = 5
Private Const mcGWHWNDNEXT = 2
Private Const mcGWLSTYLE = (-16)
Private Const mcWSVISIBLE = &H10000000
Private Const mconMAXLEN = 255
Sub ListName()
Dim xRg As Range
Dim xStr As String
Dim xStrLen As Long
Dim xHandle As Long
Dim xHandleStr As String
Dim xHandleLen As Long, xHandleStyle As Long
On Error Resume Next
Set xRg = Application.InputBox("Please select a range(single cell):", "!", ActiveWindow.RangeSelection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
xRg(1).Activate
xHandle = apiGetWindow(apiGetDesktopWindow(), mcGWCHILD)
Do While xHandle <> 0
xStr = String$(mconMAXLEN - 1, 0)
xStrLen = apiGetWindowText(xHandle, xStr, mconMAXLEN)
If xStrLen > 0 Then
xStr = Left$(xStr, xStrLen)
xHandleStyle = apiGetWindowLong(xHandle, mcGWLSTYLE)
If xHandleStyle And mcWSVISIBLE Then
ActiveCell.Value = xStr
ActiveCell.Offset(1, 0).Activate
End If
End If
xHandle = apiGetWindow(xHandle, mcGWHWNDNEXT)
AppActivate (xHandle)
Loop
End Sub
Bookmarks