Visio2002: How to Control the Size of a CommandBar by Using Visual Basic for Applications (303729)



The information in this article applies to:

  • Microsoft Visio 2002 Standard
  • Microsoft Visio 2002 Professional

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 properly 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.

REFERENCES

For additional information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

297304 Visio2002: How to Run Sample Code from Knowledge Base Articles

For the latest information, hot topics, resources, downloads, and more for the Visio Developer, go to the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/17/2005
Keywords:kbhowto kbinfo KB303729