#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default 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 ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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 ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Command Bar

Hi Bob, thanks will give it a bash.

best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
One command in one cell initiating another command in another cel. Chas52 Excel Worksheet Functions 3 November 7th 09 06:57 PM
command code ( GOTO command) in formula calan New Users to Excel 1 June 11th 09 09:44 AM
command button add another command Wanna Learn Excel Discussion (Misc queries) 5 December 7th 08 11:42 PM
Pivot Table Error Message - "Command Text not set for command obje Jeff Divian Excel Discussion (Misc queries) 0 November 7th 07 10:26 PM
I want to combine a "match" command with a copy and paste command. alomega Excel Programming 1 February 9th 05 05:52 PM


All times are GMT +1. The time now is 09:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"