WD: Using AppActivate to Switch to Another Application

Last reviewed: February 2, 1998
Article ID: Q72287
The information in this article applies to:
  • Microsoft Word 97 for Windows
  • Microsoft Word 98 Macintosh Edition
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

SUMMARY

This article contains an example macro that switches the focus from Microsoft Word to another application; when it is finished, the macro returns the focus to Word. What the macro does while switching between applications is up to the individual user.

The AppActivate statement activates the specified window in an application other than Microsoft Word. Use AppActivate to switch to another application that is already running or that you have started by using Shell. To activate a window within Word, use the Activate command.

NOTE: If the other application is minimized, this macro will not maximize that application; it simply gives that application the focus and then returns the focus to Word for Windows.

MORE INFORMATION

Word 97 for Windows or Word 98 Macintosh Edition

For more information about switching focus to another application using Word 97 for Windows or Word 98 Macintosh Edition, while in the Visual Basic for Applications Editor, click the Office Assistant, type "AppActivate" (without the quotation marks), click Search, and then click to view "AppActivate Statement". For examples of how to do this in Word 97 or Word 98, click "Example."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Visual Basic Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component

Word Versions 7.x and Earlier

The following is the text of the macro:

   Sub Main
      ActiveWin$ = WindowName$()    'get the title of the current window
      AppActivate "Microsoft Excel", 1
      Activate ActiveWin$
   End Sub

The WordBasic AppActivate syntax is as follows:

   AppActivate WindowText$ [,Immediate]

NOTE: Many applications append the name of the working file to the application name used in the window title bar. For example, the Windows Cardfile application might have window names such as:

   Cardfile - (untitled)
   Cardfile - PHONE.CRD

In this case the following AppActivate command should include the complete window text string:

   AppActivate "Cardfile - PHONE.CRD", 1

Microsoft Excel includes the working file name in the windows title bar when the spreadsheet window is maximized.

There are other methods to return the focus to Word for Windows. The main advantage of this method is its simplicity. When the macro returns the focus, Word for Windows will be in the exact state that it was left in prior to running the macro.

REFERENCES

"Microsoft Word for Windows Technical Reference," page 29

"Microsoft Word for Windows and OS/2 Technical Reference," pages 128-129


Additional query words: word6 winword word7 word95 winword winword2
macword word8 word97
Keywords : kbmacroexample macword ntword winword word7 word8 word95 word97 macword98 kbmacro
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a- CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a,97; MACINTOSH:6.0,6.0.1,98
Platform : MACINTOSH Win95 WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.