Re: Macro and Protection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




Hi Roberto
Roberto Bumbalo Wrote:
>
> It always happens when people drag and drop values. It is very easy to
> 'repair', but all formulas are locked, so I have to open the ss, unlock
> it
> and fix it.
> Can a Macro do it, as it can do it when the sheet is protected, but
> pword
> free, but is there a way to unlock it, fix the problem and the
> password
> protect it again?

Yes, if the following code is entered into the "this workbook" module
(press [alt+F11] in Excel & then [view - project explorer], a macro
could be assigned to a button to unprotect the sheet (with or without a
password), fix the problem & reprotect the sheet.

Thisworkbook code:
Private Sub Workbook_Open()
Dim Password As String: Password = "secret" ' change to personal
preference
Dim ws As Worksheet
'To password protect each sheet in the workbook
For Each ws In ActiveWorkbook.Worksheets
ws.Protect Password:=Password, *UserInterfaceOnly:=True* ' for guidance
on options search "protect method" in VBE Help
Next ws
end sub

When this is entered you can then record a macro [tools - macros -
record new macro] of the process you go through when you repair the
ref# error, assign this to a command button & it'll be problem solved!

I hope the above is enough detail for you as I'm off to bed & then work
before I'll check for any questions. If it's not, hopefully someone else
will respond to your questions.

hth, good luck,
Rob Brockett
NZ
Always learning & the best way to learn is to experience...


--
broro183
------------------------------------------------------------------------
broro183's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30068
View this thread: http://www.excelforum.com/showthread.php?threadid=506721

.



Relevant Pages

  • Re: Macro and Protection
    ... > Roberto Bumbalo Wrote: ... >> and fix it. ... > could be assigned to a button to unprotect the sheet (with or without a ... > 'To password protect each sheet in the workbook ...
    (microsoft.public.excel)
  • RE: Protect/Unprotecting Sheets with CmdButtons
    ... takefocusonclick property of the commandbutton to false to avoid problems. ... range if the worksheet is not active. ... Notice the "Protect Sheet" function is greyed out. ...
    (microsoft.public.excel.programming)
  • RE: Protect/Unprotecting Sheets with CmdButtons
    ... takefocusonclick property of the commandbutton to false to avoid problems. ... range if the worksheet is not active. ... Notice the "Protect Sheet" function is greyed out. ...
    (microsoft.public.excel.programming)
  • RE: Protect/Unprotecting Sheets with CmdButtons
    ... range if the worksheet is not active. ... "Jim Thomlinson" wrote: ... Notice the "Protect Sheet" function is greyed out. ...
    (microsoft.public.excel.programming)
  • Re: What event to use?
    ... I'm most of the logic is trying to bypass the messages that you get ... from Excel when you try to mod a protected sheet. ... Why protect the sheet when, if the correct password hasn't been ... Not sure why I'd want to unprotect when the worksheet or workbook is ...
    (microsoft.public.excel.programming)