Microsoft KB Archive/88853

{|
 * width="100%"|

Macro to Determine If the Active Window Is the Macro Window

 * }

Q88853

-

The information in this article applies to:


 * 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, version 7.0
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1

-

SUMMARY
When you run a WordBasic macro, it may generate the error message, &quot;Command is unavailable&quot; if the active window is the macro window. This problem occurs because several macro commands are unavailable if the active window is the macro editing window. Use the appropriate macro below to determine if this is the case.

Microsoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please see the following page on the World Wide Web:

"http://www.microsoft.com/partner/referral/" For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

"http://support.microsoft.com/directory/overview.asp"

Word 2.0, 6.0, 7.0
  Sub MAIN x = SelInfo(27) If x = - 1 Then MsgBox &quot;Current window is a macro window&quot; End Sub

Word for Windows version 1.x
  Sub MAIN If InStr(WindowName$, &quot;:&quot;) <> 0 And \ Mid$(WindowName$, InStr(WindowName$, &quot;:&quot;) + 1, 1) \ = &quot; &quot; Then MsgBox &quot;Current window is a macro window&quot; End Sub NOTE: You can include text in the MsgBox command with instructions to close the window if the window is a macro editing window.

MORE INFORMATION
In version 2.0, 6.0, 7.0 of Microsoft Word for Windows, the WordBasic SelInfo function can be used to return information about the current selection. The SelInfo command is not available in versions 1.x of Word for Windows. The above macro for versions 1.x of Word for Windows uses the InStr command to determine if a colon is in the window name in order to determine if a macro window is open.

The syntax for SelInfo is as follows:

  n = SelInfo(Type) Type number 27 returns the value -1 if the selection is in a macro editing window.