Microsoft KB Archive/303729

= How to control the size of a CommandBar by using Visual Basic for Applications in Visio =

Article ID: 303729

Article Last Modified on 11/28/2006

-

APPLIES TO


 * Microsoft Office Visio Professional 2007
 * Microsoft Office Visio Standard 2007
 * Microsoft Office Visio Professional 2003
 * Microsoft Office Visio Standard 2003
 * Microsoft Visio 2002 Professional Edition
 * Microsoft Visio 2002 Standard Edition

-



This article was previously published under Q303729



SUMMARY
This article contains a sample Microsoft Visual Basic for Applications (VBA) macro to create a custom CommandBar and specify its size (width).



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To correctly specify the width of a custom CommandBar in VBA, you must use the commands in the order that is specified in the following example: Public Sub AddBarTest

' Set a new CommandBar. Set cb = Application.CommandBars.Add(Temporary:=True)

' Add CommandBar Items. With cb       .Controls.Add ID:=23     ' ID for Open .Controls.Add ID:=3     ' ID for Save .Controls.Add ID:=2     ' ID for Spelling .Controls.Add ID:=4     ' ID for Print .Controls.Add ID:=18    ' ID for New Drawing .Controls.Add ID:=19    ' ID for Copy Drawing .Controls.Add ID:=3738  ' ID for Mail as Attachment .Controls.Add ID:=26    ' ID for Equation

.Visible = True

' Set the Width of the toolbar. .Width = 60 End With End Sub When you use the Application.CommandBars command to create a floating toolbar, you expect to be able to set the bar's Width property to force the bar's controls to wrap across several rows. However, this command does not usually work, and the bar contains a single row.

This behavior depends on the exact order in which you add the controls, set the width, and set the visibility. The only sequence that works is:

Add, Visible, Width

Other sequences such as

Visible, Add, Width

-or-

Add, Width, Visible

do not work as expected.

