Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Remove the Control Menu and Program Window Controls


View products that this article applies to.

This article was previously published under Q213456

↑ Back to the top


Summary

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

↑ Back to the top


More information

Use the following sample macro in conjunction with workbook protection, full-screen display, and a custom menu bar to remove the window controls on an 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 "close application" key-combination commands. 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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Sample Macro

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

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

     '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 keys.
     Application.OnKey "%{f4}"

     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

↑ Back to the top


References

For additional information about disabling control menu commands, click the article number below to view the article in the Microsoft Knowledge Base:
213502� XL2000: How to Programmatically Disable Excel Control Menu Commands

↑ Back to the top


Keywords: KB213456, kbprogramming, kbofficeprog, kbinfo, kbhowto, kbdta

↑ Back to the top

Article Info
Article ID : 213456
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 301