How could I run my macros in a protected with password worksheet

  • Thread starter Thread starter jose luis
  • Start date Start date
J

jose luis

Hi everyone!,

I am building an small application where I want the data in a workshee
be protected with a password and still be capable to run macros (Exce
2000). I been reading the messages in this forum and i get the idea t
include the protect / Unprotect instruction in the macro
(ActiveWorkbook.Unprotect Password:="abcd"). I already did that but i
doesn´t work (error 1004).

Could you give me a hand?

Thank you all.

Jos
 
The macros will still work generally when a workbook nis
protected. It is only when your try and run a command in
VBA which is not available to run when the workbook is
protected that the macro will fail. An example of this is
conditional formatting. If you protect a workbook and try
and add conditional formatting through the menu it will ot
let you. An so with VBA the commands for those same
things will not run in VBA either. If a command runs
normally off the menu when the workbook is protected then
it should run in VBA.

If you really do need to protect and unprotect on the run
then try these:

Private Sub unprotect_cells()

ActiveWorkbook.UnprotectSharing ("xxx")
ActiveSheet.Unprotect ("xxx")

End Sub

Private Sub protect_sheet()

Dim wrkbk As String

ActiveSheet.Protect ("xxxx")
wrkbk = ThisWorkbook.Name


End Sub

BOL
David C
 
Thank you David for your prompt response. I ´ll try your solution and
Let you know.

See you around

Josè Luis
 

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