ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assigning Macro by using code (https://www.excelbanter.com/excel-programming/380840-re-assigning-macro-using-code.html)

Bob Phillips

Assigning Macro by using code
 
Sub AddMenuIcon()

With Application.CommandBars("Standard").Controls.Add( _
Type:=msoControlButton, _
ID:=2950, Befo=9)
.OnAction = "myMacro"
End With
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Richard" wrote in message
...
Hello,

This is second time that I'm posting it.

Hope someone can help me with this.

I want to assign a macro( Userform1.show) to icon that I add in for
command
bar.

I use the below code to add smiley icon on command bar and I want to use
code to assign a macro.

Sub AddMenuIcon()

Application.CommandBars("Standard").Controls.Add
Type:=msoControlButton,
ID _
:=2950, Befo=9

???????? <<== Here I want to code to assign macro so that if user click
this amiley button, the userform can be poped up.

End Sub

Any help will be appreciated.

Thanks




Bob Phillips

Assigning Macro by using code
 
Existed where? already used on another button, or the image exists
somewhere? The former would be very difficult if not impossible unless you
knew all controls that might use it, the latter is simple if you know the
sheet and the image name.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Richard" wrote in message
...
Bob,

It works perfect; however, I have one more question.

Before I create Smiley face icon, I want to chack if the Smiley face is
already existed or not. If the Smiley face already existed, then I just

want
to assign the macro; otherwise, add Smiley face before assign the macro.

Can you help me with this as well, please?

Thank you so much.

"Bob Phillips" wrote:

Sub AddMenuIcon()

With Application.CommandBars("Standard").Controls.Add( _
Type:=msoControlButton, _
ID:=2950, Befo=9)
.OnAction = "myMacro"
End With
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Richard" wrote in message
...
Hello,

This is second time that I'm posting it.

Hope someone can help me with this.

I want to assign a macro( Userform1.show) to icon that I add in for
command
bar.

I use the below code to add smiley icon on command bar and I want to

use
code to assign a macro.

Sub AddMenuIcon()

Application.CommandBars("Standard").Controls.Add
Type:=msoControlButton,
ID _
:=2950, Befo=9

???????? <<== Here I want to code to assign macro so that if user

click
this amiley button, the userform can be poped up.

End Sub

Any help will be appreciated.

Thanks








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

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