+ Reply to Thread
Results 1 to 3 of 3

Custom tool bar does not transfer correctly

  1. #1
    WayneF
    Guest

    Custom tool bar does not transfer correctly


    Sorry about all these post but i think i am nearly at the end ...

    I have now created a tool bar with some buttons and dropdown menu. I did
    this in 2003. I have attached the toolbar to the workbook but when I tried
    to give this file to another use ... There is nothing on the toolbar; The
    toolbar comes up ok with the write name when the book is first opened BUT
    the are no buttons, only a very small box with the "close" cross. Does
    anyone know why this does not work ? I have tried it from 2003 to 2002 and
    from 2003 to 2003 and i get the same outcome ..... VERY small toolbar with
    no buttons.

    Thanks for you help in advance

    Wayne



  2. #2
    Bernie Deitrick
    Guest

    Re: Custom tool bar does not transfer correctly

    Wayne,

    Attaching toolbars is problematic.

    The best option is to create the commandbar on the fly, when the workbook is
    opened, and delete the commandbar when the workbook is closed. Attaching a
    commandbar to a workbook is a bad choice for a few reasons: the commandbar
    gets permanently attached to the user's library file, and will open anytime
    the user starts Excel, and then any click on the commandbutton will try to
    open your file. To get around that, follow these instructions and example
    code.

    In the workbook's Thisworkbook object code module, place the following code:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    DeleteCommandbar
    End Sub

    Private Sub Workbook_Open()
    CreateCommandbar
    End Sub

    Private Sub Workbook_WindowActivate(ByVal Wn As Window)
    On Error GoTo NotThere
    Application.CommandBars("My Bar").Visible = True
    Exit Sub
    NotThere:
    CreateCommandbar
    End Sub

    Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
    On Error Resume Next
    Application.CommandBars("My Bar").Visible = False
    End Sub

    In a regular code module, place the following:

    Dim myBar As CommandBar
    Dim myButton As CommandBarButton

    Sub CreateCommandbar()

    On Error Resume Next
    DeleteCommandBar

    Set myBar = Application.CommandBars.Add("My Bar")
    With myBar
    .Position = msoBarTop
    .Visible = True
    .Enabled = True
    Set myButton = .Controls.Add(Type:=msoControlButton, ID:=23)
    With myButton
    .Caption = "Hello"
    .Style = msoButtonIcon
    .FaceId = 137
    .Enabled = True
    .OnAction = "SayHello"
    End With
    End With

    End Sub

    Sub DeleteCommandBar()
    'Delete the commandbar if it already exists
    On Error Resume Next
    Application.CommandBars("My Bar").Delete
    End Sub

    Sub SayHello()
    MsgBox "Hello there"
    End Sub

    You can add as many buttons or other menu items as you like.

    HTH,
    Bernie
    MS Excel MVP


    "WayneF" <[email protected]> wrote in message
    news:%[email protected]...
    >
    > Sorry about all these post but i think i am nearly at the end ...
    >
    > I have now created a tool bar with some buttons and dropdown menu. I

    did
    > this in 2003. I have attached the toolbar to the workbook but when I tried
    > to give this file to another use ... There is nothing on the toolbar; The
    > toolbar comes up ok with the write name when the book is first opened BUT
    > the are no buttons, only a very small box with the "close" cross. Does
    > anyone know why this does not work ? I have tried it from 2003 to 2002 and
    > from 2003 to 2003 and i get the same outcome ..... VERY small toolbar with
    > no buttons.
    >
    > Thanks for you help in advance
    >
    > Wayne
    >
    >




  3. #3
    Registered User
    Join Date
    02-28-2004
    Location
    Oregon
    Posts
    35

    Question

    Bernie, why a WindowActivate/Deactivate routine? What is the point of that? Curious. Done this many times without it; any advantage?
    Regards,
    Zack Barresse

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1