ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   protection macro (https://www.excelbanter.com/excel-programming/293202-protection-macro.html)

Labrat

protection macro
 
I am creating a macro that changes passwords on a spreadsheet
The problem is when the spreadsheet's password isn't what is expected by the macro, and it comes up with the macro error box with the de-bug option, etc
How can I alter the macro so that when the password is not correct it displays a message box saying "invalid password", and hitting "ok" would halt the macro
Or better yet, can a macro detect a password? Or at least return a true/false statement concerning a password
Thanks in advanc
Labrat.

JE McGimpsey

protection macro
 
take a look he

http://www.mcgimpsey.com/excel/removepwords.html

In article ,
Labrat wrote:

I am creating a macro that changes passwords on a spreadsheet.
The problem is when the spreadsheet's password isn't what is expected by the
macro, and it comes up with the macro error box with the de-bug option, etc.
How can I alter the macro so that when the password is not correct it
displays a message box saying "invalid password", and hitting "ok" would halt
the macro?
Or better yet, can a macro detect a password? Or at least return a true/false
statement concerning a password?
Thanks in advance
Labrat.


Peter atherton

protection macro
 
Labrat

Something like this

x = Password

if x < password then
count = count + 1
msgbox = "Incorrect Password, try again"
if count = 3 then
Exit Sub
end if
End if

Not tested
-----Original Message-----
I am creating a macro that changes passwords on a

spreadsheet.
The problem is when the spreadsheet's password isn't what

is expected by the macro, and it comes up with the macro
error box with the de-bug option, etc.
How can I alter the macro so that when the password is

not correct it displays a message box saying "invalid
password", and hitting "ok" would halt the macro?
Or better yet, can a macro detect a password? Or at least

return a true/false statement concerning a password?
Thanks in advance
Labrat.
.


Jack

protection macro
 
Here is one way:


On Error Goto BadPW
ActiveWorkbook.Unprotect "Your password here"

BadPW:
MsgBox "Invalid Password!", vbOkOnly + vbExclamation
Exit Sub


-Jack

-----Original Message-----
I am creating a macro that changes passwords on a

spreadsheet.
The problem is when the spreadsheet's password isn't what

is expected by the macro, and it comes up with the macro
error box with the de-bug option, etc.
How can I alter the macro so that when the password is

not correct it displays a message box saying "invalid
password", and hitting "ok" would halt the macro?
Or better yet, can a macro detect a password? Or at least

return a true/false statement concerning a password?
Thanks in advance
Labrat.
.


Jack

protection macro
 
Try this exactly, it should work:


Sub CPS()

Sheets("DATA_SHEET").Select
On Error Goto BadPW
ActiveSheet.Unprotect
On Error Goto 0
ActiveSheet.Protect

Sheets("POSTING_SHEET").Select
On Error Goto BadPW
ActiveSheet.Unprotect
On Error Goto 0
ActiveSheet.Protect

ActiveWorkbook.Save
ActiveWindow.Close

Exit Sub

BadPW:
MsgBox "Invalid Password!", vbOKOnly + vbExclamation

End Sub



-----Original Message-----
Thanks everyone for your quick response!
Peter, I have no Idea how to enter your script into the

macro.
Jack, It still pops up with "invalid password" even when

it is correct.
Here is what I'm working with to give you a better idea:
Sub CPS()

Sheets("DATA SHEET").Select
On Error GoTo BadPW
ActiveSheet.Unprotect ("password")
BadPW:
MsgBox "Invalid Password!", vbOKOnly + vbExclamation
Exit Sub
ActiveSheet.Protect ("password")
Sheets("POSTING SHEET").Select
ActiveSheet.Unprotect ("password")
ActiveSheet.Protect ("password")
ActiveWorkbook.Save
ActiveWindow.Close
End Sub

Where should I place your script? How should I modify it?
Thanks in advance!
Labrat
.


Labrat

protection macro
 
Thanks but I'm getting a run-time error 9, - subscript out of range
Any Ideas?


All times are GMT +1. The time now is 03:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com