Here is my vba code below:
The first Sub creates my tool bar. When I open my visio, the toolbar is
created. I do see that. The first tool bar button that I create is called
"Offense". The caption is "Offense". When the button is click, it execute
Sub OffenseLayerActive(). I comment out many of the things to narrow down
what was happening. If I comment out
With cbButton
.Caption = " OFFENSE "
End With
and close my Visio document - No MS Visio message appears. (Its a MS Office
Visio error that indicates visio has encountered a problem and collect
informatio to be send back to Microsoft. You have a choice is sending or
not.
If I uncomment that, then close out, I do get the message.
When I do click on the button, the button caption does change to Caps. It
does work.
Thanks,
Gary
Dim visLayer1 As Integer, visLayer2 As Integer
Dim visLayer3 As Integer, visLayer4 As Integer
Dim visLayer5 As Integer
Dim NMenu As Variant
Dim cbButton1 As Office.CommandBarButton
Dim cbButton2 As Office.CommandBarButton
Dim cbButton3 As Office.CommandBarButton
Dim cbButton4 As Office.CommandBarButton
Dim cbButton5 As Office.CommandBarButton
Dim cbButton6 As Office.CommandBarButton
Dim cbButton7 As Office.CommandBarButton
Dim cbButton8 As Office.CommandBarButton
' This is version September 22, 2008
Sub AddDrawingContextNOffenseBar()
Dim cbars As Office.CommandBars
Dim cbar As Office.CommandBar
Dim cbButton As Office.CommandBarButton
Set cbars = Application.CommandBars
Set cbar = cbars.Add(Name:="N Offense", Position:=msoBarTop,
Temporary:=True)
' Set cbar = cbars.Add(Name:="Skill", Position:=msoBarTop, Temporary:=True)
cbar.Visible = True
' cbar.Protection = msoBarNoCustomize
' cbar.Context = Str(visUIObjSetDrawing) & "*"
' ***********************************************
' Active Layer Control
' ***********************************************
' Set cbButton1 = cbar.Controls.Add(Type:=msoControlButton)
Set cbButton1 = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton1
.Caption = " Offense "
.TooltipText = "Click for Offense"
.Tag = "cbbOffLayer"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.OffenseLayerActive"
End With
Set cbButton1 = Nothing
Set cbButton2 = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton2
.Caption = " Defense "
.TooltipText = "Click for Defense"
.Tag = "cbbVBAMacro"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.DefenseLayerActive"
End With
Set cbButton2 = Nothing
Set cbButton3 = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton3
.Caption = " Def Move "
.TooltipText = "Click for Def Move"
.Tag = "cbbVBAMacro"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.DefenseMovementLayerActive"
End With
Set cbButton3 = Nothing
Set cbButton4 = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton4
.Caption = " No Layer "
.TooltipText = "Click for No Layer"
.Tag = "cbbVBAMacro"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.NoLayerActive"
End With
Set cbButton4 = Nothing
' ***********************************************
' Visible Layer Control
' ***********************************************
Set cbButton = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton
.Caption = "| View Full "
.TooltipText = "Click to View Full Play"
.Tag = "cbbVBAMacro"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.AllLayerVisible"
End With
Set cbButton = Nothing
Set cbButton = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton
.Caption = " View Off "
.TooltipText = "Click To View Offense"
.Tag = "cbbVBAMacro"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.OffenseLayerVisible"
End With
Set cbButton = Nothing
Set cbButton = cbar.Controls.Add(Type:=msoControlButton, ID:=2)
With cbButton
.Caption = " View Def "
.TooltipText = "Click To View Defense"
.Tag = "cbbVBAMacro"
.Style = msoButtonCaption
'.FaceID = 7075
.OnAction = "ThisDocument.DefenseLayerVisible"
End With
Set cbButton = Nothing
End Sub
' *************************************************************************
' Controlling Active Layers with All Layers Visible
' *************************************************************************
Sub OffenseLayerActive()
Dim UndoScopeID1 As Long
Dim cbars As Office.CommandBars
Dim cbar As Office.CommandBar
Dim cbButton As Office.CommandBarButton
Dim intX As Integer
Set cbars = Application.CommandBars
Set cbar = cbars("N Offense")
For intX = 1 To cbar.Controls.Count
Set cbButton = cbar.Controls.Item(intX)
'check for mixed case first
If cbButton.Caption = " Offense " Then
'cbButton.Caption = " OFFENSE "
With cbButton
.Caption = " OFFENSE "
End With
End If
'resetting the other buttons
'If cbButton.Caption = " DEFENSE " Then
' cbButton.Caption = " Defense "
'ElseIf cbButton.Caption = " DEF MOVE " Then
' cbButton.Caption = " Def Move "
'ElseIf cbButton.Caption = " NO LAYER " Then
' cbButton.Caption = " No Layer "
'ElseIf cbButton.Caption = "| VIEW FULL " Then
' cbButton.Caption = "| View Full "
'ElseIf cbButton.Caption = " VIEW OFF " Then
' cbButton.Caption = " View Off "
'ElseIf cbButton.Caption = " VIEW DEF " Then
' cbButton.Caption = " View Def "
'End If
Next intX
End Sub