WD: Macro to Determine If the Active Window Is the Macro Window

Last reviewed: January 30, 1998
Article ID: 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
  • Word for the Macintosh, versions 6.0, 6.0.1

SUMMARY

When you run a WordBasic macro, it may generate the error message, "Command is unavailable" 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 engineers 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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/supportnet/refguide/

Word 2.0, 6.0, 7.0

   Sub MAIN
    x = SelInfo(27)
    If x = - 1 Then MsgBox "Current window is a macro window"
   End Sub

Word for Windows version 1.x

   Sub MAIN
    If InStr(WindowName$(), ":") <> 0 And \
    Mid$(WindowName$(), InStr(WindowName$(), ":") + 1, 1) \
    = " " Then MsgBox "Current window is a macro window"
   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.

REFERENCES

"Using WordBasic," by Microsoft and WexTech Systems, page 277


Additional query words: winword2 selinfo workaround
Keywords : kbmacroexample macword winword word6 word7 word95 kbcode kbmacro kbprg
Version : WINDOWS:1.x,2.x,6.0,6.0a,6.0c,7.0; MACINTOSH:6.0,6.0.1
Platform : MACINTOSH WINDOWS


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: January 30, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.