View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Kasama Kasama is offline
external usenet poster
 
Posts: 13
Default Macro doesn't work on UserInterfaceOnly-protected sheet

Yes, thanks, but the protection code is in:
Private Sub Workbook_Open()
Sheets("Name1").Unprotect Password:="pw"
Sheets("Name2").Unprotect Password:="pw"
Application.MoveAfterReturn = True
Application.MoveAfterReturnDirection = xlDown
Sheets("Name1").EnableSelection = xlUnlockedCells
Sheets("Name1").Protect Password:="pw", UserInterfaceOnly:=True,
Contents:=True, DrawingObjects:=True
Sheets("Name2").EnableSelection = xlUnlockedCells
Sheets("Name2").Protect Password:="pw", UserInterfaceOnly:=True,
Contents:=True, DrawingObjects:=True
End Sub
--
But it still doesn't work, have I missed something?

Kasama


"Norman Jones" wrote:

Hi Kasama,

Your code works for me.

However, the UserInterfaceOnly setting is not persistant between Excel
sessions. Therefore, you should consider placing the protection code in rhe
Workbook_Open procedure or, alternatively, in an Auto_Open macro in a
standard module.


---
Regards,
Norman



"Kasama" wrote in message
...
Shouldn't 'UserInterfaceOnly:=True' allow macros to change the sheet?

My worksheet has a Shape which moves to align with Column V when a macro
is
run. It works while the sheet is unprotected but when it's protected, the
macro fails (Run-time error 1004) even though protection was set for User
Interface Only.

The 'Protect' macro uses this code:
Sheets("Name").Protect Password:="password", UserInterfaceOnly:=True,
Contents:=True, DrawingObjects:=True

The 'Move' macro which aligns the drawing object selects it and uses this
code:
Selection.Left = .Columns("V").Left

I know I could add code at the beginning and end of 'Move' to Unprotect
and
Protect the sheet, but I thought that with 'UserInterfaceOnly:=True', I
should not need to do this?
--
Kasama