WD2000: WindowState Property Returns 1 (Maximized ) Instead of (2) Minimized As Expected (210253)



The information in this article applies to:

  • Microsoft Word 2000

This article was previously published under Q210253

SYMPTOMS

When you create the following Microsoft Visual Basic macro for Microsoft Word 2000
Sub newdoc()
   Application.NewWindow
   ActiveWindow.WindowState = wdWindowStateMinimize
   MsgBox ActiveWindow.WindowState
End Sub
				
and you then run the macro to create a new document window and report the state of the window, the message box indicates a maximized state (1) instead of the actual state of the new window. The new window is minimized, therefore the message box should report a minimized state (2).

In Word 97, the same macro reports a normal state (0).

CAUSE

This behavior occurs when you run the macro from a maximized Word document. Microsoft Windows returns focus to the last active window when you minimize another window. Because the last active window is maximized, the message box correctly returns a windows state of 1 (maximized).

Word 97 changes the active window to a normal (restored) state, therefore in Word 97, the message box returns a window state of 0 (normal).

When you run the macro from a restored Word 2000 document, the message box returns a window state of 0.

RESOLUTION

To resolve this issue and create a macro that returns the correct window state of the new document, follow these steps:
  1. Start Word 2000.
  2. Press ALT+F11 to start the Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. In the module sheet, type the following code:
    Sub newdoc()
       Set myWindow = Application.NewWindow
       myWindow.WindowState = wdWindowStateMinimize
       MsgBox myWindow.WindowState
    End Sub
    					
  5. Press ALT+F11 to return to Word.
  6. On the Tools menu, point to Macro, and then click Macros.
  7. Select newdoc, and then click Run. You create a new, minimized document, and the message box returns a windows state of 2 (minimized).

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

REFERENCES

For more information about the WindowState property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type windowstate property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MinorLast Reviewed:9/12/2006
Keywords:kbbug kbnofix KB210253