Bright01
asked on
Re-protecting a spreadsheet Macro
I have a worksheet that I have protected. I periodically give users the password in order for them to make changes. When they click on one of the buttons on the worksheet, I want the spreadsheet to password enable the spreadsheet again.
Sub Reactivate_Password()
ActiveSheet.Protect Password:="password"
End Sub
I have this macro embedded in the button that takes a user back to another worksheet and that's where I wanted to call this macro.
I thought this to be a simple one.
Thank you in advance.
B.
ASKER
TinTombStone,
I think that's what I've got.
Sub ReturntoQuestionaire_Click ()
'This closes the Existing sheet and returns the user to the Questionaire
Sheet42.Visible = xlSheetHidden
Reactivate_Password
Sheet1.Activate
End Sub
It doesn't work however. What am I missing?
B.
I think that's what I've got.
Sub ReturntoQuestionaire_Click
'This closes the Existing sheet and returns the user to the Questionaire
Sheet42.Visible = xlSheetHidden
Reactivate_Password
Sheet1.Activate
End Sub
It doesn't work however. What am I missing?
B.
Where is this module located? The ReturnToQuestionnaire really should be in a public module, as well as the Reactivate_Password code, and the button_click code. All should be public. If you have them embedded in a sheet's codepage, in different places (a sheet's codepage is visible only to itself, but it can reference public routines). Perhaps that's the problem.
What line do you get the error?
Here's a sample of your code in a workbook to play this out. Let me know if it works for you. See where I placed the code, and see if you did something similar.
Hope this helps!
Dave
resetPassword-r1.xlsm
What line do you get the error?
Here's a sample of your code in a workbook to play this out. Let me know if it works for you. See where I placed the code, and see if you did something similar.
Hope this helps!
Dave
resetPassword-r1.xlsm
ASKER
Dave,
Greetings! The Reactivate_Password sub is in a module.
Sub Reactivate_Password()
ActiveSheet.Protect Password:="pass"
' ActiveSheet.EnableSelectio n = xlUnlockedCells
End Sub
However, the sub is called from a worksheet sub.
Here's what's in the Worksheet.
Sub ReturntoQuestionaire_Click ()
'This closes the Maturity by Category and returns the user to the Questionaire
Sheet42.Visible = xlSheetHidden
Reactivate_Password
Sheet1.Activate
End Sub
Greetings! The Reactivate_Password sub is in a module.
Sub Reactivate_Password()
ActiveSheet.Protect Password:="pass"
' ActiveSheet.EnableSelectio
End Sub
However, the sub is called from a worksheet sub.
Here's what's in the Worksheet.
Sub ReturntoQuestionaire_Click
'This closes the Maturity by Category and returns the user to the Questionaire
Sheet42.Visible = xlSheetHidden
Reactivate_Password
Sheet1.Activate
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, can you clear your workbook of any confidential data and just upload it? I can assist more readily, then.
Dave
Dave
ASKER
Dave,
Much thanks for stepping in here.
The spreadsheet works great except when I press the "Return to Questionaire" button, it doesn't relock the sheet. The code in the specific worksheet is;
Sub ReturntoQuestionaire_Click ()
Sheet42.Visible = xlSheetHidden
Call Reactivate_Password
Sheet1.Activate
End Sub
This button returns the user to the Questionaire.
The Module that has the subroutine looks like this;
Public Sub Reactivate_Password()
ActiveSheet.Protect Password:="pass"
' ActiveSheet.EnableSelectio n = xlUnlockedCells
End Sub
I added Pulblic as you suggested and also added "call" to the routine in the spreadsheet. What's odd is that when I use the button/sub on the worksheet, it does not activate the password or protect.
B.
Much thanks for stepping in here.
The spreadsheet works great except when I press the "Return to Questionaire" button, it doesn't relock the sheet. The code in the specific worksheet is;
Sub ReturntoQuestionaire_Click
Sheet42.Visible = xlSheetHidden
Call Reactivate_Password
Sheet1.Activate
End Sub
This button returns the user to the Questionaire.
The Module that has the subroutine looks like this;
Public Sub Reactivate_Password()
ActiveSheet.Protect Password:="pass"
' ActiveSheet.EnableSelectio
End Sub
I added Pulblic as you suggested and also added "call" to the routine in the spreadsheet. What's odd is that when I use the button/sub on the worksheet, it does not activate the password or protect.
B.
can you upload?
ASKER
Dave,
Here you go. It's a mocked up version but I'm certain you will see what I'm trying to do immediately. I'm simply trying to relock the worksheet (target) when you return to the other (source) worksheet.
Thank you,
B.
Relocking-Spreadsheet.xlsm
Here you go. It's a mocked up version but I'm certain you will see what I'm trying to do immediately. I'm simply trying to relock the worksheet (target) when you return to the other (source) worksheet.
Thank you,
B.
Relocking-Spreadsheet.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you TinTombStone for providing the code. It does the job.
Thank you Dave for the comments and lesson on what I should be doing with a global macro.
Great teamwork you guys,
B.
Thank you Dave for the comments and lesson on what I should be doing with a global macro.
Great teamwork you guys,
B.
'Stuff here
Reactivate_Password
End Sub