ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reassigning a macro to an ActiveX button (https://www.excelbanter.com/excel-programming/416609-reassigning-macro-activex-button.html)

gengary

Reassigning a macro to an ActiveX button
 
I'm relatively new at using AcitveX. My issue is reassigning an AcitveX
button a new macro. How does one reassign a macro to an existing ActiveX
button which already has a macro assigned? I've exhaust all my resources here
at work and with the already posted issues with ActiveX controls here in the
help discussion board.

JLGWhiz

Reassigning a macro to an ActiveX button
 
If your button is from the Forms toolbar, then right click the button and
from the drop down menu, you should see Assign Macro. Click Assign Macro to
bring up a dialog box, click on the macro you want the button to run and it
should then appear in the top window of the dialog box. Click OK. and then
save the file. You are set.

If the button is from the Control Toolbox, then you have to enter design
mode by either clicking View Toolbars Control Toolbox and then click the
icon with the square and compass emblems in the upper left corner of the tool
bar to enter design mode, or open the Visuab Basic editor and click the icon
on the menu bar. Once in design mode, you can right click the button to
access a drop down menu. Click View Code to open the coce module for the
button. You should see this:

Private Sub CommandButton1_Click()
'Button's existing code here
End Sub

You can remove the existing code between the first and last lines and put
your new code in. Exit design mode, save the file and you are set.



"gengary" wrote:

I'm relatively new at using AcitveX. My issue is reassigning an AcitveX
button a new macro. How does one reassign a macro to an existing ActiveX
button which already has a macro assigned? I've exhaust all my resources here
at work and with the already posted issues with ActiveX controls here in the
help discussion board.


gengary

Reassigning a macro to an ActiveX button
 
Thanks for the help. I'm able to change two of the buttons, but I now have
another issue 4 of the buttons seem to have a macro or control reference
directly assigned to the button. In the properties box instead of the normal
commandbutton1, a cmdprint appears which is a sub macro in the program. How
does one change the macro assigned to the button in this case? As you can
tell I'm really new at programming.

"JLGWhiz" wrote:

If your button is from the Forms toolbar, then right click the button and
from the drop down menu, you should see Assign Macro. Click Assign Macro to
bring up a dialog box, click on the macro you want the button to run and it
should then appear in the top window of the dialog box. Click OK. and then
save the file. You are set.

If the button is from the Control Toolbox, then you have to enter design
mode by either clicking View Toolbars Control Toolbox and then click the
icon with the square and compass emblems in the upper left corner of the tool
bar to enter design mode, or open the Visuab Basic editor and click the icon
on the menu bar. Once in design mode, you can right click the button to
access a drop down menu. Click View Code to open the coce module for the
button. You should see this:

Private Sub CommandButton1_Click()
'Button's existing code here
End Sub

You can remove the existing code between the first and last lines and put
your new code in. Exit design mode, save the file and you are set.



"gengary" wrote:

I'm relatively new at using AcitveX. My issue is reassigning an AcitveX
button a new macro. How does one reassign a macro to an existing ActiveX
button which already has a macro assigned? I've exhaust all my resources here
at work and with the already posted issues with ActiveX controls here in the
help discussion board.


JLGWhiz

Reassigning a macro to an ActiveX button
 
I neglected to menton that if you have more than one button you will need to
check the name because Excel automatically numbers them as you put them on a
sheet or a UserForm. From what you described the "cmdprint" appears to be a
name assigned by a previous code writer. If I am right, then you can use
that name in lieu of the CommandButton# part of the the coce.

expl: Private Sub cmdprint_Click() 'would replace CommandButton1_Click

You can test that easy enough. Simply right click the button and the View
Code. VBA will write the Click event line for you and it will use the
appropriate name. If
it does not write the code, click in the Declarations window, the small
window at top right of the code window, and then click on "click". But I
believe for the controls they automatically display the click event code
lines.

"gengary" wrote:

Thanks for the help. I'm able to change two of the buttons, but I now have
another issue 4 of the buttons seem to have a macro or control reference
directly assigned to the button. In the properties box instead of the normal
commandbutton1, a cmdprint appears which is a sub macro in the program. How
does one change the macro assigned to the button in this case? As you can
tell I'm really new at programming.

"JLGWhiz" wrote:

If your button is from the Forms toolbar, then right click the button and
from the drop down menu, you should see Assign Macro. Click Assign Macro to
bring up a dialog box, click on the macro you want the button to run and it
should then appear in the top window of the dialog box. Click OK. and then
save the file. You are set.

If the button is from the Control Toolbox, then you have to enter design
mode by either clicking View Toolbars Control Toolbox and then click the
icon with the square and compass emblems in the upper left corner of the tool
bar to enter design mode, or open the Visuab Basic editor and click the icon
on the menu bar. Once in design mode, you can right click the button to
access a drop down menu. Click View Code to open the coce module for the
button. You should see this:

Private Sub CommandButton1_Click()
'Button's existing code here
End Sub

You can remove the existing code between the first and last lines and put
your new code in. Exit design mode, save the file and you are set.



"gengary" wrote:

I'm relatively new at using AcitveX. My issue is reassigning an AcitveX
button a new macro. How does one reassign a macro to an existing ActiveX
button which already has a macro assigned? I've exhaust all my resources here
at work and with the already posted issues with ActiveX controls here in the
help discussion board.



All times are GMT +1. The time now is 01:42 AM.

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