XL: Removing the Control Menu and Application Window Controls

Last reviewed: September 2, 1997
Article ID: Q117855
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97

SUMMARY

In Microsoft Excel, you can create a Visual Basic for applications, macro to disable or remove the application window and worksheet controls.

MORE INFORMATION

You can use the following sample macro in conjunction with workbook protection, full-screen display, and a custom menu bar to remove the window controls on a Microsoft Excel workbook. The macro limits a user's ability to control the window by removing the maximize and minimize buttons and the window's control menu box, and by disabling the application switching keystrokes.

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. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

Macro Example

'Macro To Protect the Workbook and Limit User Control
'
Sub WbProtect()

     'Trap for the ALT+F4 (close application) key combination
     Application.OnKey "%{f4}", ""

   ' Note that if you are using Microsoft Excel for Windows 95,
   ' you are unable to override CTRL+ESC, ALT+TAB, and ALT+ESC.

     'Trap for the CTRL+ESC, ALT+TAB and ALT+ESC
     '(application switching) key combinations
     Application.OnKey "^{esc}", ""
     Application.OnKey "%{esc}", ""
     Application.OnKey "%{tab}", ""

     'Turn on error handling in case the Menu bar already exists
     On Error Resume Next

     'Make sure Microsoft Excel is Maximized
     Application.WindowState = xlMaximized

     'Make sure the workbook is maximized
     ActiveWindow.WindowState = xlMaximized

     'Protect the window
     ActiveWorkbook.Protect Structure:=True, Windows:=True
     With ActiveWindow
          .DisplayHorizontalScrollBar = False
          .DisplayVerticalScrollBar = False
          .DisplayWorkbookTabs = False
          .DisplayHeadings = False
     End With

     'Set the application to full screen view
     Application.DisplayFullScreen = True

     'Create a new blank menubar
     MenuBars.Add "mybar"

     'Show the blank menu bar
     MenuBars("mybar").Activate

End Sub

'-------------------------------------------------------------------

'Macro to Restore the Control Menu
'
Sub WbUnprotect()

'Enable the ALT+F4, CTRL+ESC, ALT+ESC, and ALT+TAB keys.
     Application.OnKey "%{f4}"
     Application.OnKey "^{esc}"
     Application.OnKey "%{esc}"
     Application.OnKey "%{tab}"

     On Error Resume Next

     'Restore normal menu if worksheet is active
     MenuBars(xlWorksheet).Activate

     'Restore normal menu if modulesheet is active
     MenuBars(xlModule).Activate

     'Turn off full screen display
     Application.DisplayFullScreen = False

    'Restore window options
    With ActiveWindow
       .DisplayHorizontalScrollBar = True
       .DisplayVerticalScrollBar = True
       .DisplayWorkbookTabs = True
       .DisplayHeadings = True
    End With

     'Unprotect the workbook
     ThisWorkbook.Unprotect

End Sub

REFERENCES

For more information about disabling control menu commands, see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q107689
   TITLE     : XL: Disabling Microsoft Excel Control Menu Commands


Additional query words: xl97 7.00 5.00 API protect user Hide
Keywords : kbprg PgmApi xlvbahowto xlui kbcode kbprg
Version : 5.00 5.00c 7.00 97
Platform : 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: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.