Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default Protect a sheet

I am using the following code to lock cells and protect a sheet. When I
re-open the saved workbook, I am not prompted for a password (dash) when I
unprotect it. What is wrong with my code?
TIA
........................
Range("B7,C7,D7,E7,F7,G7,B8,C8,F8,G8,G55,G94,G95,G 144").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.Protect ("dash")
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveWorkbook.SaveAs Filename:="Test", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWorkbook.Close False
.........................

--
Ken Hudson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Protect a sheet

My first guess is that you're not opening the correct Test.xls file.

I'd test it by specifying the complete path, like:
ActiveWorkbook.SaveAs Filename:="c:\Test", .....

or add a message box after the save to double check the location.

msgbox activeworkbook.fullname



Ken Hudson wrote:

I am using the following code to lock cells and protect a sheet. When I
re-open the saved workbook, I am not prompted for a password (dash) when I
unprotect it. What is wrong with my code?
TIA
.......................
Range("B7,C7,D7,E7,F7,G7,B8,C8,F8,G8,G55,G94,G95,G 144").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.Protect ("dash")
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveWorkbook.SaveAs Filename:="Test", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWorkbook.Close False
........................

--
Ken Hudson


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Protect a sheet

think this may do what you want.

Sub Test()

With ActiveWorkbook

With .ActiveSheet

With .Range("B7,C7,D7,E7,F7,G7,B8,C8,F8,G8,G55,G94,G95, G144")
.Locked = True
.FormulaHidden = False
End With


.Protect Password:="dash", DrawingObjects:=True, Contents:=True, _
Scenarios:=True

.EnableSelection = xlUnlockedCells

End With

.SaveAs Filename:="C:\Test", FileFormat _
:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
.Close False
End With
End Sub

--
jb


"Ken Hudson" wrote:

I am using the following code to lock cells and protect a sheet. When I
re-open the saved workbook, I am not prompted for a password (dash) when I
unprotect it. What is wrong with my code?
TIA
.......................
Range("B7,C7,D7,E7,F7,G7,B8,C8,F8,G8,G55,G94,G95,G 144").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.Protect ("dash")
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveWorkbook.SaveAs Filename:="Test", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWorkbook.Close False
........................

--
Ken Hudson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default Protect a sheet

Thanks John.
Looks like the problem with my code was that the "ActiveSheet.Protect
("dash")" code should not have been coded on its own line. It needed to be
imbedded in the line above:

ActiveSheet.Protect Password:="dash", DrawingObjects:=True, Contents:=True,
Scenarios:=True

--
Ken Hudson


"john" wrote:

think this may do what you want.

Sub Test()

With ActiveWorkbook

With .ActiveSheet

With .Range("B7,C7,D7,E7,F7,G7,B8,C8,F8,G8,G55,G94,G95, G144")
.Locked = True
.FormulaHidden = False
End With


.Protect Password:="dash", DrawingObjects:=True, Contents:=True, _
Scenarios:=True

.EnableSelection = xlUnlockedCells

End With

.SaveAs Filename:="C:\Test", FileFormat _
:=xlNormal, Password:="",
WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
.Close False
End With
End Sub

--
jb


"Ken Hudson" wrote:

I am using the following code to lock cells and protect a sheet. When I
re-open the saved workbook, I am not prompted for a password (dash) when I
unprotect it. What is wrong with my code?
TIA
.......................
Range("B7,C7,D7,E7,F7,G7,B8,C8,F8,G8,G55,G94,G95,G 144").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.Protect ("dash")
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveWorkbook.SaveAs Filename:="Test", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False
ActiveWorkbook.Close False
........................

--
Ken Hudson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
protect sheet using vba Jock Excel Programming 1 February 22nd 08 03:51 PM
Protect Workbook Vs Protect Sheet Poor_pakistani New Users to Excel 4 May 25th 06 02:06 PM
Can I protect columns w/in a "List" using Protect Sheet? Diane Excel Discussion (Misc queries) 0 May 10th 06 03:30 PM
Lock and protect cells without protect the sheet Christian[_7_] Excel Programming 6 December 28th 04 04:50 PM
excel - macro code to open a protected sheet, enter passowrd, and then protect sheet arunjoshi[_5_] Excel Programming 1 May 2nd 04 03:50 PM


All times are GMT +1. The time now is 06:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"