Microsoft KB Archive/128621

From BetaArchive Wiki

Article ID: 128621

Article Last Modified on 1/19/2007



APPLIES TO

  • Microsoft Project 98 Standard Edition
  • Microsoft Project 4.1 Standard Edition
  • Microsoft Project 4.1a
  • Microsoft Project 4.0 Standard Edition



This article was previously published under Q128621

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.

  ub 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


Keywords: kbcode kbprb kbprogramming KB128621