How to set the position on the screen of the toolbars and menu bar

Article contributed by Dave Rado

You can use VBA to set the position of the toolbars and menu bar ( collectively known as CommandBars), using a number of methods.

1.

You can set a CommandBar to be docked at the top, left, right, or bottom of the Word window, or to be floating, by using the Position method. For example:

With CommandBars("Formatting")
    If .Position <> msoBarTop Then .Position = msoBarTop
End With

Using the If statement as shown above prevents unnecessary flicker. 

2.

You can set the docking order of a CommandBar relative to the other CommandBars in the same docking area by setting the RowIndex property. For example:

With CommandBars("Formatting")
    If .Rowindex <> 2 Then .Rowindex = 2 
End With

Warning: If your macro is to be run on other users' machines, you really need to set the RowIndex of all available CommandBars, or you are likely to get unpredictable results.

3.

You can set the distance (in pixels) from the left edge of the specified CommandBar to the left side of the docking area by using the Left property. The best plan is to first position your CommandBars manually where you want them to be, and get the appropriate measurements using code such as:

MsgBox CommandBars("Formatting").Left

Having found out what position you want to set a CommandBar to, you can then use code such as the following to set its position:

With CommandBars("Formatting")
    If .Left <> 36 Then .Left = 36
End With

You would really need to test for the user's screen resolution first, as well as for whether they are using  Large icons on their toolbar – setting different values as appropriate, for instance:

Res = System.HorizontalResolution
If CommandBars.LargeButtons Then

    If Val(Res) < 1024 Then

        With CommandBars("Formatting")
             If .Left <> 45 Then .Left = 45 
        End With

    ElseIf Val(Res) >= 1024 Then

        'set some other value for the Left property

    End If

ElseIf Not CommandBars.LargeButtons Then

    'etc

End If


Click to view Terms of Use page

Click to view Disclaimer page