+ Reply to Thread
Results 1 to 3 of 3

VBA Toolbar Ideas required

  1. #1
    Registered User
    Join Date
    08-18-2005
    Posts
    34

    VBA Toolbar Ideas required

    I have to create a new TOOLBAR in Excel that is generated when a specifc spreadsheet is opened. E.g. When I open a TEST spreadsheet the code looks for TEST ID and then creates a toolbar with pre-defined macro buttons.

    Does anybody know if this is possible. Any possible solutions will be hulgely and greatly received.

    I know how to create the toolbar manually but now when the document is loaded

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning moglione1

    What you're asking here is actually pretty advanced stuff. The only way I can think of doing this is by creating a toolbar "on the fly" using VBA code and show using event procedures (Workbook_Open) and delete it before the file is closed using the Workbook_Close procedure.

    The code to create a bar with one button is as follows:

    Sub MyTB()
    On Error Resume Next
    Application.CommandBars("My Toolbar").Delete
    Set TB = Application.CommandBars.Add(Name:="My Toolbar")
    Set Btn = TB.Controls.Add(Type:=msoControlButton)
    With Btn
    .FaceId = 263
    .OnAction = Macro1
    End With
    Application.CommandBars("My Toolbar").Visible = True
    End Sub

    When clicked the button will run Macro1. The image on the button is no. 263 (use the utility from the link below to see them all).

    http://www.oaltd.co.uk/DLCount/DLCou...e=BtnFaces.zip

    To delete your toolbar use this code:

    Sub KillToolbar()
    Application.CommandBars("My Toolbar").Delete
    End Sub

    That bit's nice and easy...!

    HTH

    DominicB

  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi

    Just had another thought. Why not build your toolbar, and then use a macro to unhide it when your workbook is open, and hide it away again when it closes. The toolbar will still be there, just hidden, so it won't be immediatley viewable.

    HTH

    DominicB

+ 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