'*****insert this code into a MODULE
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (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
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Type WindR 'Store running proc in structure
Name As String
hwnd As Long
cLaSS As String
End Type
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Public Sub LoadTaskList()
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
Dim dk() As WindR
Dim lpClassName As String
Dim i, k As Integer
Dim lNull As String
s = FindWindow("XLMAIN", Application.Caption)
CurrWnd = GetWindow(s, GW_HWNDFIRST)
i = 1
While CurrWnd <> 0
Parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If Length > 0 Then
If TaskName <> Application.Caption Then
lpClassName = Space(256)
ReDim Preserve dk(i)
dk(i).Name = TaskName
k = GetClassName(CurrWnd, lpClassName, 256)
dk(i).cLaSS = Left(lpClassName, InStr(lpClassName, vbNullChar) - 1)
dk(i).hwnd = CurrWnd
If dk(i).cLaSS = "IEFrame" Then _
AppActivate dk(i).Name 'if the current class="IEFRAME" (internet explorer) then activate it
i = i + 1
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
Application.Quit 'quit the application of this project
End Sub
'*******YOUR CODE
Private Sub CommandButton1_Click()
LoadTaskList
End Sub
ide