LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default command button and assign macro

#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

 
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
how do you assign a macro to a command button in Excel 2003 ns Excel Discussion (Misc queries) 5 October 25th 07 08:58 PM
Assign a macro to a command button SheriTingle Excel Discussion (Misc queries) 4 September 25th 06 06:38 PM
Assign a macro to Command Button Object dallin Excel Discussion (Misc queries) 2 July 13th 05 03:50 AM
How do I assign a macro I have created to a Command Button in Exc. Andrew7675 Excel Discussion (Misc queries) 1 March 3rd 05 08:08 PM
Assign Macro to Command Button Shunt Excel Programming 1 August 7th 03 02:07 PM


All times are GMT +1. The time now is 08:07 AM.

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"