I want to lock worksheets for outside users. But when I do it and a macro
needs to go into the worksheet, the system gives an error. So is there a way
to lock worksheets while still allowing macros to enter into the sheets and
function properly?
enginguven, you can protect the sheet with user interface only, like this
ActiveSheet.Protect UserInterfaceOnly:=True, password:=quot;123quot;
or
Sheets(quot;Sheet1quot;).Protect UserInterfaceOnly:=True, Password:=quot;123quot;
or use something like this
Const PW As String = quot;123quot; 'Change Password Here
ActiveSheet.Unprotect Password:=PW
'you code here
ActiveSheet.Protect Password:=PWEnd Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 amp; 2003
quot;enginguvenquot; gt; wrote in message
...
gt; I want to lock worksheets for outside users. But when I do it and a macro
gt; needs to go into the worksheet, the system gives an error. So is there a
way
gt; to lock worksheets while still allowing macros to enter into the sheets
and
gt; function properly?
Indeed I don't want to lock these worksheets for editing. I misled you since
I want to HIDE sheets and don't encounter any problems with macros. I don'
want outside users to see the worksheets but want macros to function properly.
quot;Paul Bquot; wrote:
gt; enginguven, you can protect the sheet with user interface only, like this
gt;
gt; ActiveSheet.Protect UserInterfaceOnly:=True, password:=quot;123quot;
gt; or
gt; Sheets(quot;Sheet1quot;).Protect UserInterfaceOnly:=True, Password:=quot;123quot;
gt;
gt; or use something like this
gt;
gt; Const PW As String = quot;123quot; 'Change Password Here
gt; ActiveSheet.Unprotect Password:=PW
gt; 'you code here
gt; ActiveSheet.Protect Password:=PWEnd Sub
gt;
gt;
gt;
gt; --
gt; Paul B
gt; Always backup your data before trying something new
gt; Please post any response to the newsgroups so others can benefit from it
gt; Feedback on answers is always appreciated!
gt; Using Excel 2002 amp; 2003
gt;
gt; quot;enginguvenquot; gt; wrote in message
gt; ...
gt; gt; I want to lock worksheets for outside users. But when I do it and a macro
gt; gt; needs to go into the worksheet, the system gives an error. So is there a
gt; way
gt; gt; to lock worksheets while still allowing macros to enter into the sheets
gt; and
gt; gt; function properly?
gt;
gt;
gt;
enginguven, you can do most things on a sheet that is hidden, like this,
Sub test1()
With Sheets(quot;Sheet1quot;)
.Range(quot;A1quot;) = 25
.Range(quot;A2quot;) = quot;Testquot;
.Range(quot;H3:H3000quot;).ClearContents
.Range(quot;G2quot;).Font.ColorIndex = 3
End With
End Sub
But if you need to unhide the sheet for the macro to run you can let the
macro unhide the sheet, run your code and then hide the sheet again, if you
hide it with xlSheetVeryHidden you want see it listed when you go to format,
sheet, you will need to lock the VBA project to keep someone from unhiding
the sheet from there. The code below will do that.
To protect the VBA project, from your workbook right-click the workbook's
icon and pick View Code. This icon is to the left of the quot;Filequot; menu this
will open the VBA editor, in Project Explorer right click on your workbook
name, if you don't see it press CTRL r to open the Project Explorer then
select VBA project properties, protection, check lock project for viewing
and set a password. Press Alt and Q to close this window and go back to your
workbook and save and close the file. Be aware that this password can be
broken by third party softwareSub test2()
Application.ScreenUpdating = False
Sheets(quot;Sheet1quot;).Visible = True
'Your code here
Sheet1.Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 amp; 2003
quot;enginguvenquot; gt; wrote in message
...
gt; Indeed I don't want to lock these worksheets for editing. I misled you
since
gt; I want to HIDE sheets and don't encounter any problems with macros. I don'
gt; want outside users to see the worksheets but want macros to function
properly.
gt;
gt; quot;Paul Bquot; wrote:
gt;
gt; gt; enginguven, you can protect the sheet with user interface only, like
this
gt; gt;
gt; gt; ActiveSheet.Protect UserInterfaceOnly:=True, password:=quot;123quot;
gt; gt; or
gt; gt; Sheets(quot;Sheet1quot;).Protect UserInterfaceOnly:=True, Password:=quot;123quot;
gt; gt;
gt; gt; or use something like this
gt; gt;
gt; gt; Const PW As String = quot;123quot; 'Change Password Here
gt; gt; ActiveSheet.Unprotect Password:=PW
gt; gt; 'you code here
gt; gt; ActiveSheet.Protect Password:=PWEnd Sub
gt; gt;
gt; gt;
gt; gt;
gt; gt; --
gt; gt; Paul B
gt; gt; Always backup your data before trying something new
gt; gt; Please post any response to the newsgroups so others can benefit from it
gt; gt; Feedback on answers is always appreciated!
gt; gt; Using Excel 2002 amp; 2003
gt; gt;
gt; gt; quot;enginguvenquot; gt; wrote in message
gt; gt; ...
gt; gt; gt; I want to lock worksheets for outside users. But when I do it and a
macro
gt; gt; gt; needs to go into the worksheet, the system gives an error. So is there
a
gt; gt; way
gt; gt; gt; to lock worksheets while still allowing macros to enter into the
sheets
gt; gt; and
gt; gt; gt; function properly?
gt; gt;
gt; gt;
gt; gt;
- Oct 22 Sun 2006 20:10
How can I lock worksheets while macros can still enter into them?
close
全站熱搜
留言列表
發表留言