The information in this article applies to:
SUMMARYIn Word, you may need to determine if a program is running. When you write WordBasic macros that communicate with other applications (through dynamic data exchange [DDE]), this determination is often necessary because prior to starting a DDE conversation using the WordBasic DDEInitiate command, the application you intend to communicate with must be running. MORE INFORMATION
Word 6.0 includes an AppIsRunning() function that can be used to determine
if an application is already running. The AppIsRunning() function returns
-1 if the specified application is running or returns 0 (zero) if it is
not.
Word for Windows
Word for the Macintosh
In Word version 2.x for Windows you can call GetModuleHandle in the
Windows Kernel dynamic-link library (DLL) to determine if an application
is running. The following Word 2.x macro example demonstrates the use of
the Windows GetModuleHandle function to determine if Microsoft Excel is
already running.
This macro checks to see if Microsoft Excel is running. The macro uses AppActivate to switch the focus to the Microsoft Excel application. If the application is not running, the Shell statement runs EXCEL.EXE. If the EXCEL directory is not in your MS-DOS path, you can indicate a full path to the Microsoft Excel executable file (Shell "C:\Excel\Excel.exe").
The GetModuleHandle function uses the module name for the application to
determine if an application is running. The module name for an application
is usually the name of the executable file.
IsAppLoaded is an alias for the GetModuleHandle function. Any name can be
used in place of the IsAppLoaded alias used in the above macro Declare
statement.
The following macro example demonstrates the use of the Windows GetModuleHandle function to determine if Microsoft Access is already running.
The following Word 2.x macro example uses the Windows GetModuleHandle
function to determine if Microsoft Excel is already running. If Excel is
already running, Word initiates a DDE conversation with Excel in order to
maximize the Excel application window.
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT
YOUR OWN RISK. Microsoft provides this macro code "as is" without
warranty of any kind, either express or implied, including but not
limited to the implied warranties of merchantability and/or fitness
for a particular purpose.
Additional query words: winword2 GetModuleHandle winword word6 running loaded macword isapploaded declare dll dde
Keywords : kbmacro kbmacroexample |
Last Reviewed: September 28, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |