MrExcel Publishing
Your One Stop for Excel Tips & Solutions

how to prompt for pw in Protect sheet macro?

Posted by robert on August 23, 2001 3:04 PM

Is there a way to prompt a user for a password while running a Protect sheet macro? activesheet.protect just automatically assings a null password. I tried utilizing the code provided in the 08/05 posting titled Protect Sheet Macro (which used a prespecified password) but I am having difficulting assigning a variable to prompt for a password to enter. Any assistance would be greatly appreciated.

Posted by Sean Tobin on August 23, 2001 3:57 PM

ActiveSheet.Protect password:="password"

it's case-sensitive, by the way

Posted by Brrett South London (sory its a little late) on August 25, 2001 10:43 AM

Password (Asks Questions)

Maybe a little bit extra needed

I have a code thats well cool ! Suggest everyone nab this one.

Sub Password_one_way_trip_xls_()
'Created by: Barrett South London
' For Mr Excel WWW 23 Aug 2001
' Good luck I just hope thisis the sort of thing you were looking for.
MyDir = Application.InputBox("Enter Location to Save File, C:\Windows\Desktop")
MyFile = Application.InputBox("Enter save File As Name")
MyPword = Application.InputBox("Enter PASSWORD")
' put tyou password you would like in cell A1 and
' DONT FORGET IT, case matters. No second chance this will
' lock the xls file for good, bar a few good crackers, ' you can never recover it.
ChDir MyDir
ActiveWorkbook.SaveAs FileName:=MyFile, _
FileFormat:=xlNormal, _
End Sub