View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Protect via Code Q

Sean,
Try something like

Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
WS.EnableSelection = xlNoSelection
WS.Protect Password:="1234"

I'll give you a piece of advice that will serve you well as you get deeper
in to Excel and VBA: Get out of the habit now, not later, of using Select in
VBA. It is (almost) never necessary to Select anything. Instead, reference a
worksheet or workbook or range or whatever directly. Don't Select anything.
Your code will be cleaner, faster, and easier to maintain.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Sean" wrote in message
ups.com...
To password protect a sheet I use a very simple piece of code, as
below, but how do I incorporate code to ensure that the "Select
Unlocked Cells" is UNCHECKED when protecting


Sub Protect()

Sheets("Sheet1").Select
ActiveSheet.Protect Password:="1234"

Thanks