Determining How Many Instances of an Application are Active

  • Thread starter Thread starter Carlton
  • Start date Start date
C

Carlton

I'm using MSAccess (VBA) to manipulate a series of MSWord documents. The
program creates a Word Application, loads and manipulates a series of
documents, then saves and closes the Word Application. The Word Application
remains hidden. I notice that if WINWORD.exe is already running, the VBA code
errors. I need to determine if Word is already running (hidden or otherwise)
then interrupt the processing if 'Yes' until the previous instance is
removed. All my MSDN references for this issue relate to API's
GetModuleHandle and GetModuleUsage, each 16-bit API's. With 32-bit,
apparently GetModuleUsage was deleted and GetModuleHandle was changed to
apiGetModuleHandle. I can't find any references to this new API in MSDN. Does
anyone know how I can determine how many instances of WINWORD.exe are running
given the current API's (or other tools)? Thanks for any advice.
 
Mr. Hargis:
Very interesting looking code set. I'll try it. Thanks for the quick and
useful response.
 
I did test this and it worked for me running AC2003 on XP Pro. Now, one
thing I found. If you use Word as your Email editor in Outlook, testing for
Word will always return true if Outlook is running.
 
This code does exactly what I wanted. And thanks for introducing me to these
new API's. Right now I don't have a clue what they did or how they did it, so
I plan to spend some time parsing this ingenious code. Thx again. (And I'm
not effected by the Outlook issue.)
 
Glad it worked for you.
As to API calls. API stands for Application Program Interface.
Windows has many dll files. Dll files are basically compiled code that
performs various activities. In the case of the Windows dlls, they work with
the operating system to perform tasks and return values. These dll files are
designed so that any language can use them; however, it is necessary to pass
exactly what they need and know how to get the return value. So, logically,
it is like using functions.

With that said, it may be difficult to understand the code because you don't
see what the API call (dll) is doing.
 
Carlton said:
This code does exactly what I wanted. And thanks for introducing me to these
new API's. Right now I don't have a clue what they did or how they did it, so
I plan to spend some time parsing this ingenious code.

Those APIs are but a subset of what is possible. Stephen Lebans has a
few interesting and useful ones at his website, www.lebans.com. To me
though the best resource that I've found is at vbnet.mvps.org. Some
useful ones I've used very recently are determining if a valid drive
exists or, hmm, I forget. But i'm usually over there every week or
month or so poking about.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Back
Top