Command Bar

L

Les Stout

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 ***
 
B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top