Microsoft KB Archive/118497

= 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:


 * Microsoft Excel for Windows, versions 5.0, 5.0c
 * Microsoft Excel for Windows 95, versions 7.0, 7.0a
 * Microsoft Excel 97 for Windows
 * Microsoft Excel for the Macintosh versions 5.0, 5.0a

SYMPTOMS
In 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.

CAUSE
When 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.

WORKAROUND
To 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 = False Screen updating is set back to True when the macro ends or if you use the statement:

Application.ScreenUpdating = True The following macro example protects Sheet2 without updating the screen:

Sub ProtectSheet2 Application.ScreenUpdating = False Worksheets(2).Protect End Sub