PC Review


Reply
Thread Tools Rate Thread

Count & Select Window

 
 
=?Utf-8?B?RWRtdW5k?=
Guest
Posts: n/a
 
      12th Oct 2006
VBA rookie here.

Is it possible to get VBA to count the number of active applications in
Windows? I don’t mean counting the number of Excel workbooks opened within
the Excel application but the number of applications that are active within
Windows itself. Say if I have launched Word, Notepad, Powerpoint, Excel and
SAP application, the count should return 5.

If this is possible, then how can I also get it to Debug.Print each
applications’ name?

Currentlly, I’m using sendkeys "%{TAB}" to tab to-and-fro the next
application. This is very dangerous. With your answer, I hope to get VBA to
activate the intended application rather than using ALT+TAB.

Thanks in advance
--
Edmund
(Using Excel XP)
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      12th Oct 2006
Edmund,

Here's the MS version:
http://support.microsoft.com/kb/175030

And similar in VB
http://vbnet.mvps.org/index.html?cod...entprocess.htm

And using WMI
http://codecomments.com/Visual_Basic/message738136.html

NickHK

"Edmund" <(E-Mail Removed)> wrote in message
news:148CA8C7-9FAF-432D-91DF-(E-Mail Removed)...
> VBA rookie here.
>
> Is it possible to get VBA to count the number of active applications in
> Windows? I don't mean counting the number of Excel workbooks opened within
> the Excel application but the number of applications that are active

within
> Windows itself. Say if I have launched Word, Notepad, Powerpoint, Excel

and
> SAP application, the count should return 5.
>
> If this is possible, then how can I also get it to Debug.Print each
> applications' name?
>
> Currentlly, I'm using sendkeys "%{TAB}" to tab to-and-fro the next
> application. This is very dangerous. With your answer, I hope to get VBA

to
> activate the intended application rather than using ALT+TAB.
>
> Thanks in advance
> --
> Edmund
> (Using Excel XP)



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      12th Oct 2006
Probably mean

http://vbnet.mvps.org/index.html?cod...pprocesses.htm

for the VB way.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"NickHK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Edmund,
>
> Here's the MS version:
> http://support.microsoft.com/kb/175030
>
> And similar in VB
> http://vbnet.mvps.org/index.html?cod...entprocess.htm
>
> And using WMI
> http://codecomments.com/Visual_Basic/message738136.html
>
> NickHK
>
> "Edmund" <(E-Mail Removed)> wrote in message
> news:148CA8C7-9FAF-432D-91DF-(E-Mail Removed)...
> > VBA rookie here.
> >
> > Is it possible to get VBA to count the number of active applications in
> > Windows? I don't mean counting the number of Excel workbooks opened

within
> > the Excel application but the number of applications that are active

> within
> > Windows itself. Say if I have launched Word, Notepad, Powerpoint, Excel

> and
> > SAP application, the count should return 5.
> >
> > If this is possible, then how can I also get it to Debug.Print each
> > applications' name?
> >
> > Currentlly, I'm using sendkeys "%{TAB}" to tab to-and-fro the next
> > application. This is very dangerous. With your answer, I hope to get VBA

> to
> > activate the intended application rather than using ALT+TAB.
> >
> > Thanks in advance
> > --
> > Edmund
> > (Using Excel XP)

>
>



 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      12th Oct 2006
Yeah, that's a bit more relevant.

NickHK

"Bob Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Probably mean
>
> http://vbnet.mvps.org/index.html?cod...pprocesses.htm
>
> for the VB way.
>
> --
> HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> "NickHK" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Edmund,
> >
> > Here's the MS version:
> > http://support.microsoft.com/kb/175030
> >
> > And similar in VB
> > http://vbnet.mvps.org/index.html?cod...entprocess.htm
> >
> > And using WMI
> > http://codecomments.com/Visual_Basic/message738136.html
> >
> > NickHK
> >
> > "Edmund" <(E-Mail Removed)> wrote in message
> > news:148CA8C7-9FAF-432D-91DF-(E-Mail Removed)...
> > > VBA rookie here.
> > >
> > > Is it possible to get VBA to count the number of active applications

in
> > > Windows? I don't mean counting the number of Excel workbooks opened

> within
> > > the Excel application but the number of applications that are active

> > within
> > > Windows itself. Say if I have launched Word, Notepad, Powerpoint,

Excel
> > and
> > > SAP application, the count should return 5.
> > >
> > > If this is possible, then how can I also get it to Debug.Print each
> > > applications' name?
> > >
> > > Currentlly, I'm using sendkeys "%{TAB}" to tab to-and-fro the next
> > > application. This is very dangerous. With your answer, I hope to get

VBA
> > to
> > > activate the intended application rather than using ALT+TAB.
> > >
> > > Thanks in advance
> > > --
> > > Edmund
> > > (Using Excel XP)

> >
> >

>
>



 
Reply With Quote
 
=?Utf-8?B?RWRtdW5k?=
Guest
Posts: n/a
 
      16th Oct 2006
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)

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      16th Oct 2006
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)
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select and count AJ Microsoft Access Queries 5 14th Apr 2010 04:44 AM
SELECT Count / Sum lmossolle Microsoft Access Queries 4 7th Oct 2009 04:57 PM
Nested select query if count > 0 otherwise select all TGW Microsoft Access 1 18th Aug 2008 02:12 PM
Select Count =?Utf-8?B?UGF1bCBEZW5uaXM=?= Microsoft Access Queries 2 2nd Dec 2005 05:45 PM
Select Count =?Utf-8?B?bmJvaGFuYQ==?= Microsoft ADO .NET 12 10th Oct 2005 04:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:09 AM.