Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Recording current state of commandbars (2000)

    Hi all,

    Is there a way of recording the current state of command bars using the workbook open event? Through code, I can disable or hide all bars except my custom bar which is OK. When leaving the book, however, is it possible to restore the commandbars that the user had open when the workbook was opened?

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recording current state of commandbars (2000)

    Will this get you started:

    <pre>Public strUserBars() As String, intUserBarsCount As Integer

    Public Sub SaveCbarInfo()
    Dim cbarCB As CommandBar
    Dim I As Integer

    Application.ScreenUpdating = False
    Application.EnableEvents = False
    On Error Resume Next
    I = 0
    For Each cbarCB In CommandBars
    If cbarCB.Visible Then
    I = I + 1
    ReDim Preserve strUserBars(1 To I) As String
    strUserBars(I) = cbarCB.Name
    End If
    Next cbarCB
    intUserBarsCount = I
    On Error GoTo 0

    End Sub
    </pre>

    Legare Coleman

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Dallas plus 20 miles or so, Texas, USA
    Posts
    876
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recording current state of commandbars (2000)

    Thanks Legare, I see how you did it, but I do not understand what the following line does:

    <pre>ReDim Preserve strUserBars(1 To I) As String
    </pre>

    specifically the "Preserve" bit. I am guessing that even though you are redimming strUserBars, it is adding a new commandbar name without losing the old names?

    Thanks,

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recording current state of commandbars (2000)

    Since I don't know how many command bars there might be, I don't know how large to make the array. I could choose an arbitrarily large number, but choose to just increase the size of the array each time I added a name to it. The preserve keeps what is already in the array after it is enlarged.
    Legare Coleman

Posting Permissions

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