![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Denver, CO, USA
Posts: 62
|
Hi - I'd like to write a macro to protect all the sheets in a workbook (in Excel 97). I don't want to protect the workbook itself, as I have found that that makes WinZip unable to compress the file by more than about 5% (so whenever I send my 5 linked files over email to a client, it would take 28M instead of a mere 8M). I'm just learning VBA and imagined that I might be able to use a method like Worksheets.Protect, but Protect is not valid for the Worksheets object. My next thought is to write a loop that would Protect each sheet... but I haven't quite got to that point of understanding VBA. Is this indeed the way? Can someone suggest code?
Thanks, Rob |
|
|
|
|
|
#2 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
This will protect each sheet with the password ps:
Code:
Sub alShts2() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets ws.Protect "ps" 'change ps to your password 'change 'protect' to 'unprotect' to unprotect each sheet Next ws End Sub Cheers, NateO [ This Message was edited by: NateO on 2002-04-30 15:06 ] |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Location: Denver, CO, USA
Posts: 62
|
That works great - thanks! But (and I should have thought of this before) now if the user knows anything about VBA, s/he can go into the VBE and learn the password. Is there any way to hide the module from public view so as to hide the password?
Thanks again, Rob |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
You can lock your Project in tools, project prop., protection...
|
|
|
|
|
|
#5 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
Or you can set up a second workbook to interact with the one in question. Insert this:
Code:
ActiveWindow.ActivateNext Either way Xl's not the most secure platform... |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Ahmedabad Gujarat
Posts: 303
|
download the file protect sheet from my website..
http://www.pexcel.com/download.htm nishith desai http://www.pexcel.com |
|
|
|
|
|
#7 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
|
Quote:
thanks Chris |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|