with sheet protection on, macro won't run to add borders around a

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If protection is off, the macro runs fine. If the sheet and worksheet
becomes protected, the macro produces a runtime error 1004 that I have no
been able to locate how to fix (Visual Basic help was of no help).

The debug points to the following:
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
 
Dim wsh as Worksheet

Set wsh=Selection.Parent
wsh.UnProtect "Password"
<Perform things on the worksheet>
wsh.Protect "Password"

Replace Password with the password of the sheet that is protected. This
password is case sensitive. If there is no password, then omit this
argument.
 
If you protect the sheet, then just like manually, code can not change the
things that are protected.

the work around is to have your code unprotect the sheet, make the change,
reprotect the sheet or look at the UserInterfaceOnly property of the protect
methods.
 
You can unprotect and re-protect the sheet in the macro. I would tell
you how, but I don't have Excel on the PC I'm writing this on and I
don't trust my memory to provide the correct syntax.

If you need example code and no one else offers any, reply to this and
I'll work something up. (To help with getting a solution: What version
of Excel are you using?)
 

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