Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word commandbars.TOP (Word2000+)

    I've read everything (this forum, Google Groups, MSKB) I can find on this problem, and can't find a working solution. I suspect that Word.commandbars(index).Top is just downright trashed. Maybe coupled with the Data key problem in the registry. Nonetheless, if anyone wants a tough nut, here it is.

    I wrote a lovely "best fit" algorithm for toolbars, and it works. And it delivers the correct results (row Number, left etc.) for whatever collection of toolbars is visible on my screen.
    When I try to assign the Top value (increasing by, say, 26 for each row), it doesn't work. It is as if Word ignores the .Top setting, as shown in the attached JPG

    (later) I should add that when I debug.print the .Top value within the loop, it does not appear to change at all. It's as if the .Top setting is read-only.
    <pre>Public lngTop As Long
    Public Function DockCommandBars(lngPosition As Long, lngScreen As Long)
    ' Adapted from http://support.microsoft.com/kb/201965/en-us
    Dim cBar As CommandBar
    Dim lngLeft As Long
    ' Loop through each CommandBar in Word.
    For Each cBar In ActiveDocument.CommandBars
    If cBar.Enabled And cBar.Visible Then
    Application.StatusBar = cBar.Name ' keep track of what's going on
    If lngLeft > lngScreen Then ' want to start a new "line" of command bars
    lngLeft = 0 ' reset left edge of next available position
    lngTop = lngTop + 26 ' add what appears to be a standard hight to the position relative to the top of the screen
    End If
    CommandBars(cBar.Name).Left = lngLeft
    CommandBars(cBar.Name).RowIndex = msoBarRowLast
    CommandBars(cBar.Name).Top = lngTop
    lngLeft = lngLeft + CommandBars(cBar.Name).Width ' prepare for next command bar position
    CommandBars(cBar.Name).Position = lngPosition
    Else
    End If
    Next
    End Function
    Sub TESTDockCommandBars()
    ' Call DockCommandBars(msoBarLeft)
    ' Call DockCommandBars(msoBarRight)
    Call DockCommandBars(msoBarTop, 400)
    ' Call DockCommandBars(msoBarBottom)
    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Word commandbars.TOP (Word2000+)

    Top only applies to floating commandbars, not to commandbars docked at the top. You could try to set the RowIndex instead.

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word commandbars.TOP (Word2000+)

    Very nice. Thanks for sharing!

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word commandbars.TOP (Word2000+)

    Thanks, Hans. I got confused. I see a path now and will report back ....
    ... getting there! I have to fine-tune it because I want my wide MRUse bar on the same row as the Small Standard bar; apart from that, everything goes into place.

    I suspect my (and others) confusion stems from terminology; .Top usually suggests a pixel-like distance from the top of the screen (as in controls on GUI forms).
    (later) My technique is to establish the maximum-used RowIndex and then start with a value one greater than that. (Once again highlighting the utility of lng vs. int!)

    <pre>Option Explicit
    Public lngTop As Long
    Public Function lngMaxRow(doc As Document) As Long
    ' Adapted from http://support.microsoft.com/kb/201965/en-us
    Dim cBar As CommandBar
    Dim lngLeft As Long
    Dim lngMax As Long
    ' Loop through each CommandBar in Word.
    For Each cBar In ActiveDocument.CommandBars
    If (cBar.BuiltIn) Then ' not interested
    Else
    If cBar.RowIndex <= 0 Then ' not interested
    Else
    Debug.Print cBar.Name, cBar.RowIndex
    If lngMax < cBar.RowIndex Then
    lngMax = cBar.RowIndex
    Else
    End If
    End If
    End If
    Next
    lngMaxRow = lngMax
    End Function
    Public Function resetCB(doc As Document, lngScreen As Long, ByRef lngMax As Long) As Long
    ' Adapted from http://support.microsoft.com/kb/201965/en-us
    Dim cBar As CommandBar
    Dim lngLeft As Long
    ' Loop through each CommandBar in Word.
    For Each cBar In ActiveDocument.CommandBars
    Application.StatusBar = cBar.Name ' keep track of what's going on
    If lngLeft > lngScreen Then ' want to start a new line of command bars
    lngLeft = 0 ' reset left edge of next available position
    lngMax = lngMax + 1 ' add what appears to be a standard hight to the position relative to the top of the screen
    End If
    If (cBar.BuiltIn) Then ' not interested
    Else
    If cBar.RowIndex <= 0 Then ' not interested
    Else
    cBar.Left = lngLeft
    lngLeft = lngLeft + cBar.Width
    cBar.RowIndex = lngMax
    End If
    End If
    Next
    End Function
    Sub TESTDockCommandBars()
    Dim lngMax As Long
    lngMax = lngMaxRow(ActiveDocument)
    lngMax = lngMax + 1
    Call resetCB(ActiveDocument, 600, lngMax) ' screen 600 pixels for test purposes.
    End Sub
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •