Excel Pop Up Box to Unprotect All Worksheets When First Opening Excel

chinga

New Member
Joined
Jun 9, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi Im trying to make a pop up box automatically bring itself up when opening excel so i can unprotect all the worksheets in one go.
Im using the below code to automatically Protect all my worksheets when i close the excel, but want something that prompts a password when re-opening.

I would just normally lock the file in the Save As, Tools etc option but the file is part of a sharepoint and this way really mucks up the file.

I need a macro to help with this issue.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Update by Extendoffice 2018/1/24
Dim xSheet As Worksheet
Dim xPsw As String
xPsw = "PASSWORD"
For Each xSheet In Worksheets
xSheet.Protect xPsw
Next
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Could be a solution, to be pasted in ThisWorkBook's module:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
    Dim xSheet As Worksheet
    Dim xPsw   As String
    Dim answer As String
    answer = MsgBox("Do you want to unprotect all your sheets ?", vbYesNo)
    If answer = vbYes Then
        xPsw = "PASSWORD"
        For Each xSheet In Worksheets
            xSheet.Unprotect xPsw
        Next
        MsgBox "Done!"
    End If
End Sub
 
Upvote 0
Could be a solution, to be pasted in ThisWorkBook's module:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
    Dim xSheet As Worksheet
    Dim xPsw   As String
    Dim answer As String
    answer = MsgBox("Do you want to unprotect all your sheets ?", vbYesNo)
    If answer = vbYes Then
        xPsw = "PASSWORD"
        For Each xSheet In Worksheets
            xSheet.Unprotect xPsw
        Next
        MsgBox "Done!"
    End If
End Sub
Hi rollis13 that works perfect.

Is there a way to bring up a password box instead of a yes or no message box?

Thanks so much
 
Upvote 0
How about this:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
    Dim xSheet As Worksheet
    Dim xPsw   As String
    Dim answer As String
    xPsw = "PASSWORD"
    answer = InputBox("Input password if you want to unprotect" & vbLf & "all your sheets then press OK.")
    If answer = xPsw Then
        For Each xSheet In Worksheets
            xSheet.Unprotect xPsw
        Next
        MsgBox "Done!"
    End If
End Sub
but you could have done that by yourself ;).
 
Upvote 0
Solution
How about this:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
    Dim xSheet As Worksheet
    Dim xPsw   As String
    Dim answer As String
    xPsw = "PASSWORD"
    answer = InputBox("Input password if you want to unprotect" & vbLf & "all your sheets then press OK.")
    If answer = xPsw Then
        For Each xSheet In Worksheets
            xSheet.Unprotect xPsw
        Next
        MsgBox "Done!"
    End If
End Sub
but you could have done that by yourself ;).
Thanks so much for that worked a treat. Sorry im only learning at the moment lol how does one start learning about VBA script.
 
Upvote 0
Always set new goals and keep working on them (with or without help), sooner or later it gets into your head :).
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0
Always set new goals and keep working on them (with or without help), sooner or later it gets into your head :).
Thanks for the positive feedback(y), glad having been of some help.
Cheers thanks for that ill have to get started on some basic code.

Also I was wondering with the above code, is it possible to make it that if someone puts the wrong password in, the screen goes blank/black so they cant see what the sheets say?
 
Upvote 0
In the Workbook_Open before asking the password set the focus on an empty sheet, and, just to be sure, when saving use event Workbook_BeforeClose to do the same.
All you need is a Worksheets("Sheet2").Select (adjust sheet name as needed)
 
Upvote 0
Hi rollis13 thanks so much for all this, its working a treat. Can i use the same macro in WORD?
 
Upvote 0
In the Workbook_Open before asking the password set the focus on an empty sheet, and, just to be sure, when saving use event Workbook_BeforeClose to do the same.
All you need is a Worksheets("Sheet2").Select (adjust sheet name as needed)
Hi rollis13 thanks so much for all this, its working a treat. Can i use the same macro in WORD?
 
Upvote 0

Forum statistics

Threads
1,223,744
Messages
6,174,253
Members
452,553
Latest member
red83

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