ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Command button (https://www.excelbanter.com/excel-programming/290190-command-button.html)

Nick

Command button
 
Hi,

Can anyone tell me how to insert a command button that
will initiate a macro?

Thanks in advance,

Nick

Robert Couchman

Command button
 
Hi,

if you wish to insert a button, what you need to do is
right click on your tool bar and select the option that
says 'Form'.
on this new tool menu you should have a button
called 'Button' if you then draw a box you will have a
button.
if you right click on the button and there is not an
option for 'Macro' then you will need to click on the
button and look in the formula bar, if the word 'EMBEDED'
is in this bar, delete it.
now when you right click on the button you have an option
to attach a macro!

Have fun!

Robert Couchman

Bob Phillips[_6_]

Command button
 
Nick,

I presume you mean in Excel, not on a userform?

Three ways:

Make sure the Forms menu is open (ToolsCustomizeToolbars), click the
button control, then on the worksheet right-click and size the button. You
will immediately be presented with a dialog box to assign a macro to he
button.

OR

Make sure the Control Toolbox toolbar is open (same way), click the button
control, then on the worksheet right-click and size the button. Then double
click the button and you will be taken to the VBE with a button click event
macro set-up where you can call your macro, or even add the code there.
Click the Design mode button on this control to exit Design.

OR

Add a button to a toolbar (ToolsCustomizeCommands) and select the Macros
option, then drag either the smiley or the text item onto an existing
toolbar. Right click the new button, and there is an option to assign a
macro.

--

HTH

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

"Nick" wrote in message
...
Hi,

Can anyone tell me how to insert a command button that
will initiate a macro?

Thanks in advance,

Nick




hadrien

Command button
 
Hello Nick,

Have you tried to use the macro recorder in
Tools/Macro/Record new macro ... ?

Record a macro with the recorder and add a button to any
existing commandbar - using the Customize... dialog,
picking a button and dropping it into a commandar, then
take it out and back onto the customize dialog. Once
you're done, you should be able to see a new module in
the VB Editor.

Use this code and the following one :

With CommandBars(Your commandbar name).Controls(your
control's index)
.Caption = (set the caption)
.OnAction = (name of the macro to be initiated
.FaceId = (set the appearance of the button)
End With

you should use the OnAction property.

-----Original Message-----
Hi,

Can anyone tell me how to insert a command button that
will initiate a macro?

Thanks in advance,

Nick
.



All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com