Protecting Command Buttons

D

Dan Sweetwood

Hello everyone

I have sent this one out before but was unable to get it resolved. I have a worksheet that is the result of a csv file that is created on a daily basis from a cashregister then using macros the sales data is input into the approiate days of the month. Each day has a command button assigned to that day's macro. Everything works like a charm except that the owner wants to protect the sheet and on the days he is closed each week have those command buttons not be available. I have searched for command button properties that will lock the button so that when the sheet is protected you can not run that day's macro. All that the lock feature does is make the button uneditable but the macro still runs. Any solutions would be much appreciated

Dan Sweetwood
 
B

Bob Phillips

Dan,

Make the button non-visible on the days that you it to be non-runnable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Dan Sweetwood said:
Hello everyone,

I have sent this one out before but was unable to get it resolved. I have
a worksheet that is the result of a csv file that is created on a daily
basis from a cashregister then using macros the sales data is input into the
approiate days of the month. Each day has a command button assigned to that
day's macro. Everything works like a charm except that the owner wants to
protect the sheet and on the days he is closed each week have those command
buttons not be available. I have searched for command button properties that
will lock the button so that when the sheet is protected you can not run
that day's macro. All that the lock feature does is make the button
uneditable but the macro still runs. Any solutions would be much
appreciated!
 
D

Dan Sweetwood

thanks for the reply. I have not found how to make the button not visible. Can you help? Thanks, Dan
 
B

Bob Phillips

If it a forms button then use

activesheet.shapes("Button 1").visible =false

If it is a control toolbox button, then use

ActiveSheet.OLEObjects("CommandButton1").Visible=False

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Dan Sweetwood said:
thanks for the reply. I have not found how to make the button not visible.
Can you help? Thanks, Dan
 
D

Dave Peterson

I'm not quite sure if this fits as well's as Bob suggestion, but maybe you could
either add some code to your buttons to check the day (some algorithm???) or
even just check the protection of the worksheet:

Option Explicit
Private Sub CommandButton1_Click()

If Me.ProtectContents = True _
Or Me.ProtectDrawingObjects = True _
Or Me.ProtectScenarios = True Then
MsgBox "Hey, this won't work--the sheet's protected"
Exit Sub
End If

'rest of code here.
End Sub


I used the commandbutton from the ControlToolbox toolbar--hence, the me. stuff.
 
Top