Nothing "Cannot be done" it is a hiccup at most -
Below I am posting a couple code that will loop through all sheets in your file and constrain the scroll area to A1 -
Private Sub Workbook_Open()
Dim wb As Workbook
Dim ws As Worksheet
Dim Pwd As String
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set wb = ActiveWorkbook
Pwd = "YOURPASSWORD"
For Each ws In wb.Worksheets
ws.Unprotect Password:=Pwd
ws.ScrollArea = "$A$1:$A$1"
Call Protect_WS(ws, Pwd)
Next ws
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
It calls on Protect_WS which is to password protect each sheet individually and apply properties that you desire...
Be sure to change the True/False to the desired protection
Sub Protect_WS(ws As Worksheet, Pwd As String)
ws.Protect _
Password:=Pwd, _
DrawingObjects:=False, _
Contents:=True, Scenarios:=False, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, _
AllowInsertingColumns:=True, _
AllowInsertingRows:=True, _
AllowInsertingHyperlinks:=True, _
AllowDeletingColumns:=True, _
AllowDeletingRows:=True, _
AllowSorting:=True, _
AllowFiltering:=True, _
AllowUsingPivotTables:=True
End Sub
IF YOU DONT WANT TO PASSWORD PROTECT INDIVIDUAL SHEETS THEN CHANGE THE CODE TO THIS FOR OPEN_WORKBOOK
Private Sub Workbook_Open()
Dim wb As Workbook
Dim ws As Worksheet
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.ScrollArea = "$A$1:$A$1"
Next ws
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.EnableEvents = True
End With
End Sub
Here is a file with the code embedded on a blank sheet.
TESTME.xlsm
Password is the file name "TESTME"
NOTE - By locking down the area to just $A$1 this will prevent the user from being able to navigate around the sheet... is that what you really want? Personally I would lock areas to used ranges... but I do not know the desired outcome so for now... See if this works for what you were attempting...
Bookmarks