How To Close Application.CommandBars?

G

Gary

I am getting a MS error when I close the following VBA code in Visio 2003.

Can someone tell me know do I close this VBA code correctly, so I don't get
an error.

The VBA Code I am using is shown below.


Thanks

Gary


Dim UndoScopeID1 As Long
Dim intX As Integer

Set cbars = Application.CommandBars
Set cbar = cbars("Bar1")
If o < cbar.Controls.Count Then
For intX = 1 To cbar.Controls.Count
Set cbButton = cbar.Controls(intX)
'check for mixed case first
If cbButton.Caption = " D Move " Then
cbButton.Caption = " D MOVE "
End If
'resetting the other buttons
If cbButton.Caption = " OF " Then
cbButton.Caption = " Of "
ElseIf cbButton.Caption = " NO LAYER " Then
cbButton.Caption = " No Layer "
ElseIf cbButton.Caption = "| VIEW FULL " Then
cbButton.Caption = "| View Full "
ElseIf cbButton.Caption = " VIEW OF " Then
cbButton.Caption = " View Of "
End If
Next intX
cbButton = Nothing
End If
 
G

Gary

I don't get any error in the VBA code.

After closing the Visio drawing (embedded as an OLE Object), MS Office Visio
gives the following error message "Microsoft Office Visio has encountered a
problem
and needs to close". Then there are two buttons to select sending the
data to Microsoft or not to sent it.

Gary
 
G

Gary

John:

I just discovered that the following VBA code help cause the error message
as show in my previous posting.

If cbButton.Caption = " D Move " Then
cbButton.Caption = " D MOVE "
End If


What I am doing, is that I created a menu button with the caption " D Move".
When the button is selected, I change the captions to "D MOVE". I am
changing the menu tool caption dynamically.

I think I am doing it incorrectly, but it does change.


Any ideas??


Thanks,

Gary
 
P

Paul Herber

I am getting a MS error when I close the following VBA code in Visio 2003.

Can someone tell me know do I close this VBA code correctly, so I don't get
an error.

The VBA Code I am using is shown below.

Dim UndoScopeID1 As Long
Dim intX As Integer

First, several variables are undefined, add
Dim cbars As CommandBars
Dim cbar As CommandBar
Dim cbButton As CommandBarButton

Set cbars = Application.CommandBars
Set cbar = cbars("Bar1")

Does this command bar exist?
 
G

Gary

Those variables are defined. I just did paste all of the vba code.

I am not getting any VBA compile error.

I created this command bar eariler in my code, and when I click one of the
button on my new command bar, it execute this code. The purpose of this
code was to change the caption of the click button from lower case to all
upper case to give feedback to the user that it was click.

I think I am getting the error by Visio (only on closing of the visio
document itself) because I am changing the caption on an existing command bar
button. The want I am doing seems to work, but Visio generates an message
only on the complete closing of the visio document.

Thanks,

G
 
P

Paul Herber

Those variables are defined. I just did paste all of the vba code.

I am not getting any VBA compile error.

I created this command bar eariler in my code, and when I click one of the
button on my new command bar, it execute this code. The purpose of this
code was to change the caption of the click button from lower case to all
upper case to give feedback to the user that it was click.

I think I am getting the error by Visio (only on closing of the visio
document itself) because I am changing the caption on an existing command bar
button. The want I am doing seems to work, but Visio generates an message
only on the complete closing of the visio document.

The error is occuring because of some error condition in or being
created by your code (sorry!). Copy and paste the whole subroutine
here, and what is the event that causes the code to run?
 
G

Gary

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
 
P

Paul Herber

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

Dim cbButton1 As Office.CommandBarButton

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


What happens if you set the TooltipText first instaed of the caption,
I reckon you'll get the same error on that line. So, it's probably
cbButton1 that isn't being set.
So, check tha validity of cbButton1.
 

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