Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
The same event handler for two CommandBar buttons
The same event handler for two CommandBar buttons
I add custom command There are who similar XLA AddIns which add commandbars. The names of commandbars are different and are formed from the name of the corresponding xla file. But the event handlers have the same names; it leads to the fact that clicking on a button of any commandbar calls identical event handler. To be exact, the handler from the file, which has been opened in the first instance, is called. I suppose that the same ID of the buttons causes the problem, but I failed to add a button with my own ID. Is there a solution for this issue? Thank you! Here is my code: Option Explicit Option Compare Text Public strCommandBarName As String Const strParameters = "Parameters" Sub AddCommandBar() Dim c As CommandBar Dim CB As CommandBarButton Dim cp As CommandBarPopup On Error Resume Next strCommandBarName = ThisWorkbook.Name strCommandBarName = Replace(strCommandBarName, ".xla", "") Set c = Application.CommandBars(strCommandBarName) If Not c Is Nothing Then Application.CommandBars(strCommandBarName).Delete End If Set c = Application.CommandBars.Add(strCommandBarName, msoBarTop, False, False) c.Enabled = True c.Visible = True Set CB = c.Controls.Add(msoControlButton, 1) CB.Style = msoButtonIconAndCaption CB.Caption = strParameters CB.OnAction = ThisWorkbook.Name & "!" & "OnActionParameters" CB.FaceId = 304 End Sub Sub DeleteCommandBar() Dim c As CommandBar On Error Resume Next Set c = Application.CommandBars(strCommandBarName) If Not c Is Nothing Then Application.CommandBars(strCommandBarName).Delete End If End Sub Private Sub OnActionParameters() MsgBox ThisWorkbook.Name End Sub Function GetMyIndex() As String Dim FileName As String FileName = ThisWorkbook.Name FileName = Replace(FileName, ".xla", "") GetMyIndex = Mid(FileName, Len("ReplaceOnMask") + 1) End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Event handler | Excel Programming | |||
Clipboard Event Handler? | Excel Programming | |||
Event handler is invalid | Excel Programming | |||
where is the workbook_open event handler??? | Excel Programming | |||
different IDispatch in event handler | Excel Programming |