Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default password protect a macro on a command button

Hi

There is a Command Button on my worksheet that I only want selected users to
be able to use.

Is there some simple code I can put at the start of the Macro so that unless
"Yes" is typed in to cell A1, the Macro doesnt activate when the button is
pressed

Many thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default password protect a macro on a command button

Something like the following may suffice:

Sub ButtonClick()
If StrComp(ThisWorkbook.Worksheets("Sheet1").Range("A 1").Value, "yes",
vbTextCompare) < 0 Then
' cell A1 is not 'yes'.
Exit Sub
End If
''''''''''''''''''''''''''
' rest of your code here
''''''''''''''''''''''''''
End Sub



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

"dave caizley" wrote in message
...
Hi

There is a Command Button on my worksheet that I only want selected users
to
be able to use.

Is there some simple code I can put at the start of the Macro so that
unless
"Yes" is typed in to cell A1, the Macro doesnt activate when the button is
pressed

Many thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default password protect a macro on a command button

hi

i've worked with this one:

Dim flag As Boolean
Private Sub CommandButton1_Click()
If LCase(Range("a1")) = "yes" Then flag = True: yourmacro Else flag =
False: yourmacro
End Sub

Sub yourmacro()
MsgBox flag
End Sub

--
Regards,

Halim



"dave caizley" wrote:

Hi

There is a Command Button on my worksheet that I only want selected users to
be able to use.

Is there some simple code I can put at the start of the Macro so that unless
"Yes" is typed in to cell A1, the Macro doesnt activate when the button is
pressed

Many thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default password protect a macro on a command button

Hi Chip

Thanks for the reply

Being a novice to macros I think I have not fully understood what I need to
have at the start of the Macro. I guess its the sub part being repeated but
hopefully you can guide me. In case I havent made my self fully clear, I just
want the command button to be inactive unless the correct input has been
made. I dont want it to run into a debugger programme that will confuse the
users

Here is my macro including your content

Sub Review5()
'
' review5 Macro
' Macro recorded 04/06/2007 by DCaizley
'
Sub ButtonClick()
If StrComp(ThisWorkbook.Worksheets("Sheet1").Range("A 1").Value, "yes",
vbTextCompare) < 0 Then
'cell A1 is not 'yes'.
Exit Sub
'End If
Rows("95:102").Select
Selection.EntireRow.Hidden = False
Rows("94:94").Select
Selection.EntireRow.Hidden = True
Range("L30").Select
ActiveCell.FormulaR1C1 = " Limit Changes &"
Range("e95").Select
End Sub

Hope you can put me straight

Many thanks

"Chip Pearson" wrote:

Something like the following may suffice:

Sub ButtonClick()
If StrComp(ThisWorkbook.Worksheets("Sheet1").Range("A 1").Value, "yes",
vbTextCompare) < 0 Then
' cell A1 is not 'yes'.
Exit Sub
End If
''''''''''''''''''''''''''
' rest of your code here
''''''''''''''''''''''''''
End Sub



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

"dave caizley" wrote in message
...
Hi

There is a Command Button on my worksheet that I only want selected users
to
be able to use.

Is there some simple code I can put at the start of the Macro so that
unless
"Yes" is typed in to cell A1, the Macro doesnt activate when the button is
pressed

Many thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default password protect a macro on a command button

The code I posted allows the command button to be active and enabled all the
time. If, however, Range("A1") is not "yes", the code does nothing, existing
immediately. If, on the other hand, you want to completely disable the
command button, use code like the following in the Sheet module of the
worksheet that contains the button.

Private Sub CommandButton1_Click()
MsgBox "Hello World"
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If StrComp(Target.Value, "yes", vbTextCompare) = 0 Then
Me.CommandButton1.Enabled = True
Else
Me.CommandButton1.Enabled = False
End If
End If
End Sub


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





"dave caizley" wrote in message
...
Hi Chip

Thanks for the reply

Being a novice to macros I think I have not fully understood what I need
to
have at the start of the Macro. I guess its the sub part being repeated
but
hopefully you can guide me. In case I havent made my self fully clear, I
just
want the command button to be inactive unless the correct input has been
made. I dont want it to run into a debugger programme that will confuse
the
users

Here is my macro including your content

Sub Review5()
'
' review5 Macro
' Macro recorded 04/06/2007 by DCaizley
'
Sub ButtonClick()
If StrComp(ThisWorkbook.Worksheets("Sheet1").Range("A 1").Value, "yes",
vbTextCompare) < 0 Then
'cell A1 is not 'yes'.
Exit Sub
'End If
Rows("95:102").Select
Selection.EntireRow.Hidden = False
Rows("94:94").Select
Selection.EntireRow.Hidden = True
Range("L30").Select
ActiveCell.FormulaR1C1 = " Limit Changes &"
Range("e95").Select
End Sub

Hope you can put me straight

Many thanks

"Chip Pearson" wrote:

Something like the following may suffice:

Sub ButtonClick()
If StrComp(ThisWorkbook.Worksheets("Sheet1").Range("A 1").Value, "yes",
vbTextCompare) < 0 Then
' cell A1 is not 'yes'.
Exit Sub
End If
''''''''''''''''''''''''''
' rest of your code here
''''''''''''''''''''''''''
End Sub



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

"dave caizley" wrote in message
...
Hi

There is a Command Button on my worksheet that I only want selected
users
to
be able to use.

Is there some simple code I can put at the start of the Macro so that
unless
"Yes" is typed in to cell A1, the Macro doesnt activate when the button
is
pressed

Many thanks



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
password protect unhide sheet command jimmill Excel Discussion (Misc queries) 1 February 24th 09 10:08 PM
password protect the button in Excel? cfman Excel Programming 4 March 2nd 07 10:03 PM
password protect the button in Excel? cfman Excel Discussion (Misc queries) 3 March 2nd 07 09:06 PM
protect command button bill_morgan_3333 Excel Programming 4 October 29th 04 05:08 AM
Command Button Password Cindy Excel Programming 3 January 14th 04 04:32 PM


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

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

About Us

"It's about Microsoft Excel"