Edmund,
If you know which the class name of the app and/or it's title you are trying
to "connect" to, then FindWindow API would be easier.
I assume all the running processes are of no concern to you.
<From 'KPD-Team 1998: URL:
http://www.allapi.net/ :E-Mail:
(E-Mail Removed)>
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) 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 Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal
nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) +
"Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Show the window
ShowWindow WinWnd, SW_SHOWNORMAL
'Create a buffer
lpClassName = Space(256)
'retrieve the class name
RetVal = GetClassName(WinWnd, lpClassName, 256)
'Show the classname
MsgBox "Classname: " + Left$(lpClassName, RetVal)
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
</From 'KPD-Team 1998: URL:
http://www.allapi.net/ :E-Mail:
(E-Mail Removed)>
NickHK
"Edmund" <(E-Mail Removed)> wrote in message
news:0731F000-1051-4C60-B4EB-(E-Mail Removed)...
> I'm really a rookie with VBA & almost no knowledge of VB.
>
> I've followed
> http://vbnet.mvps.org/index.htmlcode...pprocesses.htm , copied
> its codes into VBA & successfully run tested it where it return results on
> the "processes" that are active in Windows. The results are exactly like
what
> I get to see in Task Manager's Tab #2. But this is not exactly what I
needed.
>
> What I actually need is contained within Tab # 1 (tab named: Applications)
> in Task Manager. For example, say if there are 10 tasks listed in tab #1
of
> Task Manager, how can I get VBA to "Switch To" the task that I needed?
>
> (a) How can I get VBA to list down each tasks in a spreadsheet or by
> Debug.Print (the list of tasks' in Task Manger Tab #1).
> (b) After achieving the above, how can I get VBA to "Switch To" the task
of
> my choice? I need the above steps for assurance because my procedure will
> later be using SendKeys to perform data entry on a NON-MS Office based
> application.
>
> I'm aware that [Application.SendKeys "%{TAB <repeatition #>}", True] can
> help do the switching but it's simply too dangerous because it does not
> verify if it has activated the intended screen. It will be a disaster if
my
> data entry (via SendKeys) is consequently executed on the wrong screen.
>
> Thanking you in advance for the big favor.
>
> --
> Edmund
> (Using Excel XP)
>