Tag in CommandBar

  • Thread starter Thread starter Desert Piranha
  • Start date Start date
D

Desert Piranha

Hi all,

I have read help etc. but i'm still in the dark. Could someone explai
to me the
uses for "Tag" when dealing with Command Bars?
IE:
'.Tag =
'.Caption =
'.OnAction =
'.Parameter =
'.FaceId =
'.Style =
'.BeginGroup =
'.TooltipText
 
Hi Desert

Here is a example that add a control to the Cell menu
(When you right click on a cell)

Sub AddToCellDropDown()
Dim CellDropDown As CommandBar
Dim MyDropDownItem As CommandBarControl

RemoveFromCellDropDown

Set CellDropDown = Application.CommandBars("Cell")
With CellDropDown.Controls.Add(Type:=msoControlButton, before:=1)
.Caption = "Try me"
.Style = msoButtonIconAndCaption
.FaceId = 59
.OnAction = ThisWorkbook.Name & "!Your_macro"
.Tag = "MyDropDownItem"
End With
End Sub

Sub RemoveFromCellDropDown()
Dim MyDropDownItem As CommandBarControl
Set MyDropDownItem = Application.CommandBars.FindControl(Tag:="MyDropDownItem")
If Not MyDropDownItem Is Nothing Then
MyDropDownItem.Delete
End If
Set MyDropDownItem = Nothing
End Sub

Sub Your_macro()
MsgBox "Hi there."
End Sub
 
Hi Ron,

Thanks for your input here,

So as i can see the "Tag" is just kinda like a Name for the command
Bar. Right?

So it is another way of doing this:

'Delete Command Bar
Application.CommandBars("cell").Controls("Try me").Delete
or
'Makes Command Bar temporary
With .Controls.Add(Type:=msoControlButton, temporary:=True)

And "Tag" will work with any kind of Command Bars?

And would there be any other uses for "Tag" other than deleting the
Command Bar?

Thx
Dave said:
Hi Desert

Here is a example that add a control to the Cell menu
(When you right click on a cell)

Sub AddToCellDropDown()
Dim CellDropDown As CommandBar
Dim MyDropDownItem As CommandBarControl

RemoveFromCellDropDown

Set CellDropDown = Application.CommandBars("Cell")
With CellDropDown.Controls.Add(Type:=msoControlButton, before:=1)
.Caption = "Try me"
.Style = msoButtonIconAndCaption
.FaceId = 59
.OnAction = ThisWorkbook.Name & "!Your_macro"
.Tag = "MyDropDownItem"
End With
End Sub

Sub RemoveFromCellDropDown()
Dim MyDropDownItem As CommandBarControl
Set MyDropDownItem =
Application.CommandBars.FindControl(Tag:="MyDropDownItem")
If Not MyDropDownItem Is Nothing Then
MyDropDownItem.Delete
End If
Set MyDropDownItem = Nothing
End Sub

Sub Your_macro()
MsgBox "Hi there."
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Desert Piranha"
message
 
Hi

I use it only for this but you can als use Enabled = False for example
Look on the MSDN site for more info
 

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

Back
Top