Using protection with passwords withiin macros

M

Mikey May

I have several worksheets that are opened individually,
data copied onto another worksheet then the data deleted
from the original worksheet.

I want to use a password on the protection of the
individual sheets and run the macro without having to type
a password in each time (there are about 15 worksheets
from which data is collarted then deleted). Another
problem i have is when the macro protects the worksheet
again it protects without a password.

Is there a way of writing the password into the macro?
 
F

Frank Kabel

Hi
try
activesheet.unprotect password:="your_password"

and
activesheet.protect password:="your_password"
 
I

ianripping

yeah there is.

i think its like: -

Sub ProtectSheet()
Dim Password 'This line of code is optional
Password = "1234"
ActiveSheet.Protect Password, True, True, True
End Sub

to protect and .......


Sub UnProtectSheet()
Password = "1234"
ActiveSheet.Unprotect Password
End Sub

to unprotect
 
M

mjack003

Hi Mike,

It would look something like:

Activeworkbook.Worksheets("Test").Unprotect("-password- ")

Copy/Paste

Activeworkbook.Worksheets("Test").Protect("-password- ")

Note your password will be visible in your code and can be viewed b
anyone who knows of VBA.

Best Regards,
Mjac
 
D

Dave Peterson

But you could protect the project:

Inside the VBE:
Tools|VBAProject Properties|Protection Tab

But it won't stop all from snooping--but it'll stop then non-dedicated!
 
Top