Article ID: 181297
Article Last Modified on 8/21/2007
Sub DockCommandBars()
Dim cBar As CommandBar
Dim intHres As Integer
Dim intVres As Integer
' Get screen resolution. Subtract 60 from each screen dimension
' to account for toolbars that are barely visible on the screen.
intHres = System.HorizontalResolution - 60
intVres = System.VerticalResolution - 60
' Loop through each CommandBar in Word.
For Each cBar In ActiveDocument.CommandBars
' If the CommandBar is beyond screen limits, then
' dock the CommandBar to the top of the Word window.
If cBar.Top > intVres Or cBar.Left > intHres Then
CommandBars(cBar.Name).Position = msoBarTop
cBar.Visible = True
End If
Next
End Sub
To dock a single toolbar, type the following line in a blank macro and run
the macro:
ActiveDocument.CommandBars(<commandbar name>).Position=msoBarTopwhere <commandbar name> is the name of the single toolbar you want to dock.
173707 OFF97: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Keywords: kbdtacode kbhowto kbmacroexample KB181297