#1. There are two different types of buttons you can use on a worksheet.
The first is from the control toolbox toolbar. You just double click on it and
put your code within that sub.
The second is from the Forms toolbar. You put your code in a General module.
Then add the button. When you've added it, you'll be prompted to assign the
macro to the button. (You can right click on it later and then assign the macro
if you weren't ready.)
#2. If you protect the worksheet, then the buttons will be safe.
#3. Inside the VBE, you can protect your project.
Select your project and then Tools|VBAProject Properties|Protection Tab
Give it a memorable password and check that box to lock from viewing.
#4. From the Control toolbox toolbar:
Option Explicit
Private Sub CommandButton1_Click()
MsgBox "HI"
Me.CommandButton1.Visible = False
'or
Me.CommandButton1.Enabled = False
End Sub
You could hide it or disable it. (and show it later/enable it later).
From the Forms toolbar:
Option Explicit
Sub testme01()
MsgBox "Yo"
With ActiveSheet.Buttons(Application.Caller)
.Enabled = True
'or
.Visible = False
End With
End Sub
"RichardO <" wrote:
Hello all:
I am just learning how to use vba in excel.
I have a code that I would like to
1) assign to a command button, how do I do this?
2) I also don't want users to be able to move or delete the command
button, how do I do this.
3) Can I protect the code in the command button so that users can't
change the code?
4) Also, is it possible for me to disable the button once it has been
clicked once, so that users don't keep on running the code once it's
been executed once?
Thanks much for all your help.
Richardo.
---
Message posted from http://www.ExcelForum.com/
--
Dave Peterson