Check to see icon exist in command bar
Sub test2()
Dim cb As CommandBarButton On Error Resume Next Set cb = Application.CommandBars.FindControl(Id:=2950) On Error GoTo 0 If cb Is Nothing Then MsgBox "no smily", , "sad" Else MsgBox cb.OnAction, , "smile" End If End Sub Regards, Peter T "Richard" wrote in message ... Hello, The code below is to add the Smiley Icon in command bar and assign "myMacro" while excel file is openning so that whenever user click on the Smiley Icon, program process the "myMacro" coding. The issue is that I don't want to add another Smiley Icon, if the Smile icon already has been added and assigned with "myMacro" while excel opened in prior use. How can I check to see whether it is already exist or not. If it is already existed on command bar, then I just want to assign a macro on the Smiley icon; otherwise, I want to add the smiley icon and assign a macro. Please help. Sub AddMenuIcon() With Application.CommandBars("Standard").Controls.Add( _ Type:=msoControlButton, _ ID:=2950, Befo=9) .OnAction = "myMacro" End With End Sub |
All times are GMT +1. The time now is 02:49 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com