Protect entire workbook - including unprotected cells

edwardzbrown

New Member
Joined
Jun 12, 2017
Messages
20
I've created a button that saves as the workbook with a custom name with the word "report". It' Puts the words "Locked Report" on every sheet. Problem is, it's not locked. Part of my functionality of this workbook is I have control buttons create customized entry fields. Some cells are protected and others are not so my sheet is user proof and also able to insert new entry ranges. Well, when I create the "generate report" (save as) button, it locks the workbook (ActiveWorkbook.Protect ("password"), True, True) but locking the workbook doesn't even lock the same way lock sheet does. Furthermore, locking the sheet doesn't lock the cells that are unprotected. But locking each sheet gets me close to what I want.

Should I make a code to protect every sheet individually? what does protect workbook do? It doesn't seem to protect anything. That's my first and second question.

I'm thinking if I can't lock unprotected cells, It's good enough to protect the worksheets because that prevents cell selection (whether protected or not) which is enough. But the buttons that create custom ranges are still functioning. Could I create a macro to clear out my code in each of the modules I created? This "report" is just a locked down freeze frame of where the document is at. The original is preserved with all the macros. I'm thinking that a clear/delete Module 1-5 would work, and keep the save-as button in module 6.

HTML:
Sub Button9_Click()'Save Report Button on Dashboard'need to add a way to lock the entire report and add LOCKED text to bodyActiveWorkbook.RefreshAll 'so refreshing
'unlock sheetActiveSheet.Unprotect ("password")

    Sheets("Dashboard").Select        Range("K9").Select        ActiveCell.FormulaR1C1 = "Locked Report"
    Sheets("Revision History").Select        Range("C4").Select        ActiveCell.FormulaR1C1 = "Locked Report"

    Sheets("A10").Select        Range("E5").Select        ActiveCell.FormulaR1C1 = "Locked Report"
    Sheets("A20").Select        Range("E5").Select        ActiveCell.FormulaR1C1 = "Locked Report"            Sheets("B10").Select        Range("E5").Select        ActiveCell.FormulaR1C1 = "Locked Report"        'etc. There are more sheets, I deleted out of this example because you get the idea. 
'save as code    Dim part1 As String    Dim part2 As String            part1 = Month(['Revision History'!A2]) & "-" & Day(['Revision History'!A2]) & "-" & Year(['Revision History'!A2])        part2 = Range("Dashboard!A5").Value                ActiveWorkbook.SaveAs Filename:=relativePath & part1 & " " & part2 & " Report.xlsm", FileFormat:= _        xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
MsgBox "This is your generated report. Close out and open your A-SCR2 document to continue working", vbInformation, "A-SCR2"
'lock sheetActiveWorkbook.Protect ("password"), True, TrueEnd Sub

I really think that deleting select modules is all I need to make this Generate Report button work for me. Is that possible?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
When protecting sheet I manually make sure that the "select unprotected cells" is unchecked. Recorded it comes out as below.

Code:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=TrueActiveSheet.EnableSelection = xlNoSelection

Code:
'To unlock sheet
Sheets("NameOfSheet").Unprotect Password:="PTTO"

'do some code stuff

'To relock sheet
Sheets("NameOfSheet").Protect Password:="PTTO"
 
Upvote 0

Forum statistics

Threads
1,217,249
Messages
6,135,477
Members
449,940
Latest member
Yna26

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