ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Command Bar (https://www.excelbanter.com/excel-programming/345518-command-bar.html)

Les Stout[_2_]

Command Bar
 
Hi all, is it possible to know, with code, which button has been
activated with vba as i would like to use an if statement. I create the
bar with the code below.

Sub addToolbarQ()
'
Application.DisplayAlerts = False
Dim oCBMenuBar As CommandBar
Dim oCBCLeave As CommandBarControl
Dim iMenu As Integer
Dim i As Integer
On Error Resume Next
Application.CommandBars("ZA-TM-RECON").Delete
Application.IgnoreRemoteRequests = True
Set oCBMenuBar = Application.CommandBars.Add(Name:="ZA-TM-RECON")
With oCBMenuBar
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.FaceId = 3
.TooltipText = "Save file"
.OnAction = "restoreToolbarsQ"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 4
.TooltipText = "Print Document"
.OnAction = "GetPeriodQ1"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 271
.TooltipText = "Save Recon to process later"
.OnAction = "SaveToQuery1"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 363
.TooltipText = "Send this document to the supplier"
.OnAction = "InsertColumnsQ"
End With
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.FaceId = 108
.TooltipText = "Adopt all changes"
.OnAction = "AdoptAllPriceDiff"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 387
.TooltipText = "Adopt changes individually"
.OnAction = "AdoptPriceDiffSep"
End With
' With .Controls.Add(Type:=msoControlButton)
' .FaceId = 157
' .TooltipText = "Last month"
' .OnAction = "lastMonth"
' End With
' With .Controls.Add(Type:=msoControlButton)
' .BeginGroup = True
' .Caption = "Summary"
' .Style = msoButtonCaption
' .TooltipText = "Show summary sheet"
' .OnAction = "gotoSummary"
' End With
.Position = msoBarTop
.Protection = msoBarNoMove
.Visible = True
End With
End Sub



Les Stout

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_6_]

Command Bar
 
Hi Les,

You can use CommandBars.ActionControl to get at any of the properties of the
activated button, such as Caption, Tag or Parameter.

So each onACtion should point to the same macro, then test as mentioned, and
call subservient macros appropriately.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Les Stout" wrote in message
...
Hi all, is it possible to know, with code, which button has been
activated with vba as i would like to use an if statement. I create the
bar with the code below.

Sub addToolbarQ()
'
Application.DisplayAlerts = False
Dim oCBMenuBar As CommandBar
Dim oCBCLeave As CommandBarControl
Dim iMenu As Integer
Dim i As Integer
On Error Resume Next
Application.CommandBars("ZA-TM-RECON").Delete
Application.IgnoreRemoteRequests = True
Set oCBMenuBar = Application.CommandBars.Add(Name:="ZA-TM-RECON")
With oCBMenuBar
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.FaceId = 3
.TooltipText = "Save file"
.OnAction = "restoreToolbarsQ"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 4
.TooltipText = "Print Document"
.OnAction = "GetPeriodQ1"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 271
.TooltipText = "Save Recon to process later"
.OnAction = "SaveToQuery1"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 363
.TooltipText = "Send this document to the supplier"
.OnAction = "InsertColumnsQ"
End With
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.FaceId = 108
.TooltipText = "Adopt all changes"
.OnAction = "AdoptAllPriceDiff"
End With
With .Controls.Add(Type:=msoControlButton)
.FaceId = 387
.TooltipText = "Adopt changes individually"
.OnAction = "AdoptPriceDiffSep"
End With
' With .Controls.Add(Type:=msoControlButton)
' .FaceId = 157
' .TooltipText = "Last month"
' .OnAction = "lastMonth"
' End With
' With .Controls.Add(Type:=msoControlButton)
' .BeginGroup = True
' .Caption = "Summary"
' .Style = msoButtonCaption
' .TooltipText = "Show summary sheet"
' .OnAction = "gotoSummary"
' End With
.Position = msoBarTop
.Protection = msoBarNoMove
.Visible = True
End With
End Sub



Les Stout

*** Sent via Developersdex http://www.developersdex.com ***




Les Stout[_2_]

Command Bar
 
Hi Bob, thanks will give it a bash.

best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***


All times are GMT +1. The time now is 10:25 AM.

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