Using protection with passwords withiin macros

  • Thread starter Thread starter Mikey May
  • Start date Start date
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?
 
Hi
try
activesheet.unprotect password:="your_password"

and
activesheet.protect password:="your_password"
 
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
 
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
 
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top