Locking a Sheet

CRE_finance_guy

New Member
Joined
Dec 3, 2021
Messages
30
Office Version
  1. 2021
Platform
  1. Windows
My model has a dashboard page full of graphs, and I'd like to lock it, so it's just a single image with no functionality. In other words, the cells aren't selectable, the charts aren't selectable, and scrolling is disabled. I have been able to achieve this (with Properties and ScrollArea, and protecting the sheet), but then I found out that the changes don't save.

Does anyone know how to achieve this in a way that actually saves?

Thanks for any help. Much appreciated!
 
Did you unlock the sheet at workbook open
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
VBA Code:
Private Sub Workbook_Open()
Sheets("Sheet1").unprotect
Sheets("Sheet1").ScrollArea = "A1:F100" 'change the sheet name and range to suit your needs
Sheets("Sheet1").protect
End Sub
 
Upvote 0
VBA Code:
Private Sub Workbook_Open()
Sheets("Sheet1").unprotect
Sheets("Sheet1").ScrollArea = "A1:F100" 'change the sheet name and range to suit your needs
Sheets("Sheet1").protect
End Sub
This doesn't work either. I tried the earlier code on a completely unprotected sheet, and it didn't work on that either, so removing protection isn't the problem. I'm curious, is this working for you?
 
Upvote 0
How could such simple code not work? Here's the goal, and the code I'm using. I just need to fix the scroll area of a particular sheet, but the "ScrollArea" feature in sheet properties does not save with a file. Instead, it resets itself every time you re-open a workbook. So I need a VBA solution to simply reset the ScrollArea property to where I want it each time a user opens the file.

Here is the code I've been using:

Private Sub Workbook_Open()
Sheets("Dashboard").ScrollArea = "$L$6"
End Sub

If I run the code, it works. So I know it's functional if I can just get it to run upon opening. However, when I save the file, close the workbook, and reopen it, the code won't run automatically.

This is an XLSM file, the sheet is unprotected, and I've tried inserting the module into "ThisWorkbook" and also into the specific sheet in question (which is "Dashboard"). I've also tried using the actual sheet number (in this case, "Sheet3" instead of "Dashboard").

I'm really hoping there's a VBA pro out there who can tell me what I'm doing wrong. Or maybe there's some weird quirk in Excel causing this particular type of code to not automatically execute upon opening the workbook.

THANK YOU in advance for any help. Much appreciated!
 
Upvote 0
That code has to go into the ThisWorkbook module. It should then run as long as macros are enabled.
 
Upvote 0
That code has to go into the ThisWorkbook module. It should then run as long as macros are enabled.
Yeah, as I said, I tried that already. I put it in ThisWorkbook, and then when that didn't work I put it in the actual sheet. Neither way works.

I also just read another thread on this forum whose author has the identical problem. Evidently no solution was found for him either. With all the VBA gurus on this site I'm really surprised that there's no solution to this.

Below is the other thread I'm referring to. I'm starting to think this might be some kind of glitch in Excel. Limit scroll area permanently
 
Upvote 0
What happens when you run the code in other than the Workbook_Open event handler ? like if Sheets("Dashboard").ScrollArea = "$L$6" is executed from a SUB in a standard module ? Does it work then ?
 
Upvote 0
Will this work for you :
In the ThisWorkbook Module
VBA Code:
Private Sub Workbook_Open()
    Application.OnTime Now, Me.CodeName & ".SetScrollArea"
End Sub

Private Sub SetScrollArea()
    Sheets("Dashboard").ScrollArea = "$L$6"
End Sub
 
Upvote 0
Will this work for you :
In the ThisWorkbook Module
VBA Code:
Private Sub Workbook_Open()
    Application.OnTime Now, Me.CodeName & ".SetScrollArea"
End Sub

Private Sub SetScrollArea()
    Sheets("Dashboard").ScrollArea = "$L$6"
End Sub
Hi Jaafar. Thanks for the thought. Unfortunately this doesn't work either.
 
Upvote 0
What happens when you run the code in other than the Workbook_Open event handler ? like if Sheets("Dashboard").ScrollArea = "$L$6" is executed from a SUB in a standard module ? Does it work then ?
I've tried to run this code in both the ThisWorkbook, and also the worksheet in question, and I've also removed "private", so that it just starts with "Sub Workbook_Open()". None of it works. Have you tried this code yourself? Maybe there's something wrong with my version of Excel (I'm using the latest version).
 
Upvote 0

Forum statistics

Threads
1,215,363
Messages
6,124,505
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top