![]() |
Help on Macro
Good morning. A couple of weeks ago, someone from this forum, was very
helpful in my question on how to unprotect protected worksheets, with similar passwords, with a macro. Below is a copy of the VB script I was given. It worked but then I realized, the password "hi" is now visible under the macro script. Is there a way to rewrite the code so that it will not show the password and instead when the macro is run, one has to enter the password before the macro can unprotect the protected worksheets? thank you very much, Storm Option Explicit sub testme() dim myPWD as string dim wks as worksheet myPWD = "hi" for each wks in activeworkbook.worksheets wks.unprotect password:=mypwd next wks end sub |
Help on Macro
You could encrypt the password and then unencrypt it when you need to use it.
But easier would be to protect the workbook's project. Inside the VBE select your project Tools|VBAProject Properties|Protection tab Lock it for viewing and give it a memorable password. Be aware that this password isn't going to stop the really dedicated--but it will keep most people out. Storm wrote: Good morning. A couple of weeks ago, someone from this forum, was very helpful in my question on how to unprotect protected worksheets, with similar passwords, with a macro. Below is a copy of the VB script I was given. It worked but then I realized, the password "hi" is now visible under the macro script. Is there a way to rewrite the code so that it will not show the password and instead when the macro is run, one has to enter the password before the macro can unprotect the protected worksheets? thank you very much, Storm Option Explicit sub testme() dim myPWD as string dim wks as worksheet myPWD = "hi" for each wks in activeworkbook.worksheets wks.unprotect password:=mypwd next wks end sub -- Dave Peterson |
Help on Macro
Use an InputBox statement to prompt the user, like so:
Sub UnlockAllWorksheets() Dim strPassword As String Dim ws As Worksheet strPassword = InputBox("Enter the password for all worksheets: ", _ "Unlock Worksheets") For Each ws In ActiveWorkbook.Worksheets ws.Unprotect password:=strPassword Next ws End Sub -- Regards, Bill Renaud |
All times are GMT +1. The time now is 09:09 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com