Microsoft Knowledge Base |
|
XL: Worksheets Activated When Protection Is Applied |
|
|
Last reviewed: December 17, 1996
Article ID: Q118497 |
|
The information in this article applies to:
SYMPTOMSIn Microsoft Excel, you can use a Visual Basic for Applications macro to protect a worksheet. However, when you do this, the worksheet will be activated briefly when the protection is applied.
CAUSEWhen you use a Visual Basic macro to protect a sheet, the worksheet will be activated briefly while the sheet is being protected. The focus returns to the sheet that was active at the time the routine was called. This behavior is by design of Microsoft Excel.
WORKAROUNDTo avoid the screen redraw and updating while protecting a sheet in a Visual Basic macro, add the following line to your macro to set the ScreenUpdating property of the application to False:
Application.ScreenUpdating = FalseScreen updating is set back to True when the macro ends or if you use the statement:
Application.ScreenUpdating = TrueThe following macro example protects Sheet2 without updating the screen:
Sub ProtectSheet2()
Application.ScreenUpdating = False
Worksheets(2).Protect
End Sub
REFERENCESFor more information about the ScreenUpdating property, click the Search button in Visual Basic Help and type:
ScreenUpdating |
|
KBCategory: kbprg kbcode
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |