Microsoft KB Archive/117855

= Removing the Control Menu and Application Window Controls =

Article ID: 117855

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0c

-



This article was previously published under Q117855





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
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. 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.

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

