How do I unprotect/with password to run marco and protect

G

Guest

I have a locked sheet with columns unlocked for users to populate. I have it
protected with a password so users can only update certain cells. I wrote a
macro to sort data when entries are completed by clicking a button. How can
I unprotect it with password, run macro, and protect it with password after
sort is complete
 
C

Chip Pearson

Try something like

ThisWorkbook.Worksheets("Sheet1").Unprotect Password:="whatever"
' sort
ThisWorkbook.Worksheets("Sheet1").Protect Password:="whatever"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
D

Dave Peterson

option explicit
sub yourmacro()
activesheet.unprotect password:="topsecret"
'your sort code here
activesheet.protect password:="topsecret"
end sub
 
G

Guest

Try adapting these to meet your needs:

Private Sub Workbook_Open()
' Perform this when workbook opened.
' Macro recorded 06/15/00 by Lou Mullen
Worksheets("Recall").Select
Application.ActiveWorkbook.Protect Password:="YourCode"
range("A1").Select
ActiveSheet.Unprotect
Selection.Sort Key1:=range("A1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ActiveSheet.Protect
Application.CommandBars("Recall Macros").Visible = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Perform steps on exit Macros
'Macro recorded 06/15/00 by Lou Mullen
Application.EnableCancelKey = xlDisabled
If Application.CommandBars("Recall Macros").Enabled = True Then
If Application.CommandBars("Recall Macros").Visible = True Then
Application.CommandBars("Recall Macros").Visible = False
End If
Application.ActiveWorkbook.Unprotect Password:="YourCode"
Application.CommandBars("Recall Macros").Delete
Else
Application.CommandBars("Recall Macros").Enabled = False
Application.ActiveWorkbook.Unprotect Password:=YourCode"
End If
End Sub

HTH Lou
 
G

Guest

Password = "sandy crotch"

Can you put it into my macro, below, so I can cut and paste? So it
unprotecteds the sheet (sandy crotch) and password protects it (sandy crotch)

Sub sort_of()
'
' sort_of Macro
' Macro recorded 2/10/2006 by Julianne
'

'
ActiveSheet.Unprotect
Range("A16").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Sort Key1:=Range("AF16"), Order1:=xlDescending,
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A16").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
 
D

Dave Peterson

Sub sort_of()
'
' sort_of Macro
' Macro recorded 2/10/2006 by Julianne
'

'
ActiveSheet.Unprotect password:="sandy crotch"
Range("A16").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Sort Key1:=Range("AF16"), Order1:=xlDescending, _
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A16").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, password:="sandy crotch"
End Sub
 
G

Guest

I received a "syntax error". The last line (ActiveSheet.Protect. . .) was
highlighted blue.

(e-mail address removed)
 
G

Guest

Didn't work. Don't give up on me. I'll hold out until tonigh. If I can't
figure it out, I'll send with out my button.
 
D

Dave Peterson

Your other post said you got it working????

J_Will said:
Didn't work. Don't give up on me. I'll hold out until tonigh. If I can't
figure it out, I'll send with out my button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top