PRJ: Minimize Argument in AppExecute Does Not Work

ID: Q128621

The information in this article applies to:

SYMPTOMS

When you use the AppExecute method with the Window and Minimize arguments, the Minimize argument does not work correctly: setting the Minimize argument to True does not minimize a non-minimized window, and setting the Minimize argument to False does not restore a maximized window.

WORKAROUND

If an application window has a control menu, then a Microsoft Project macro can change the window state of the application by using the AppActivate statement to activate it, and by using the SendKeys statement to select Restore, Minimize, or Maximize from the control menu.

It may also be possible to use DDE or OLE Automation to change the window state of an application. Some applications, including Microsoft Project and Microsoft Word, have the AppRestore, AppMinimize, and AppMaximize statements/methods. Some applications, including Microsoft Project and Microsoft Excel, have the WindowState property, which can be set to 1, 2, or 3 to restore, minimize, or maximize the application window. The examples below illustrate these techniques.

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

Example 1

The following Microsoft Project macro assumes Notepad is running. The macro activates Notepad, uses SendKeys to minimize it, and then reactivates Microsoft Project.

   Sub Ex1_SendKeys()

      'Activate Microsoft Notepad
      AppActivate "Notepad"

      '(The SendKeys string should represent the ALT+Space Bar
      ' followed by R, N, or X).
      'ALT+Space Bar, then the N key
      SendKeys "% N"

      'Reactive Microsoft Project
      AppActivate "Microsoft Project"

   End Sub

Example 2

The following Microsoft Project macros assume Microsoft Word is running. The first macro uses DDEExecute to minimize Microsoft Word, and the second uses OLE Automation. Both macros use Microsoft Word's AppMinimize statement/method.

   Sub Ex2_DDEExecute()

      'establish communication with Microsoft Word's System topic
      DDEInitiate "Winword", "System"

      'maximize Microsoft Word
      DDEExecute "[AppMinimize]"
      DDETerminate

   End Sub

   Sub Ex2_OLE_Automation()

      'declare variables
      Dim w As Object

      Set w = CreateObject("Word.Basic")

      'maximize Microsoft Word
      w.AppMinimize

   End Sub

Example 3

The following Microsoft Project macro assumes Microsoft Excel is running. It uses OLE Automation to minimize Microsoft Excel using the WindowState property.

   Sub Ex3_OLE_Automation()

      'declare variables
      Dim x As Object

      Set x = GetObject(, "Excel.Application")

      'minimize Microsoft Excel
      x.WindowState = 2 'Minimize
   End Sub

STATUS

Microsoft has confirmed this to be a problem in the products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

For more information about the AppExecute Method, choose the search button in Microsoft Project Visual Basic Reference Help, and type

   AppExecute

Additional query words: 4.00
Keywords          : kbcode kbprg
Version           : 4.0 4.1 4.1a 98
Platform          : WINDOWS
Issue type        : kbprb

Last Reviewed: November 25, 1997