Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Thanked 0 Times in 0 Posts

    Control values explaination (VBA)

    In the following script, what do the ID and Before values set? I assumed that the ID would show the button's placement on a toolbar, but not sure about the Before value. Was trying to copy and paste to add multiple buttons, and found I did not know how to change those two values accordingly for each new button added.

    Set oControl = oBar.Controls.Add(ID:=1, Before:=1)
    oControl.OnAction = "InsertandCopy"
    oControl.Style = msoButtonCaption
    oControl.Caption = "InsertandCopy"
    oControl.TooltipText = "Inserts New Columns/Rows and copies info"
    Set oControl = Nothing
    Set oBar = Nothing

    Thanks - Sat.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 16 Times in 16 Posts

    Re: Control values explaination (VBA)

    The ID property of a commandbar control is always 1 for custom controls, and specifies the action for built-in controls. For example, the File | Open... menu item and the corresponding toolbar button both have ID = 23, and the Edit | Copy menu item and the corresponding toolbar button both have ID = 19. If you are creating buttons for user-defined macros, you don't need to specify ID, it will be 1 automatically.

    The Before property specifies where you want to insert the new control created by Add. If you specify Before:=7, the new control will be inserted before (i.e. to the left of or above) the 7th control on the toolbar or menu. Before:=1 means insert at the very beginning. If you omit the Before argument, the control will be added at the end.

Posting Permissions

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