Consulting

Results 1 to 4 of 4

Thread: Solved: Dynamic placement of buttons

  1. #1
    VBAX Newbie
    Joined
    Dec 2006
    Posts
    4
    Location

    Question Solved: Dynamic placement of buttons

    I have a macro that generates several tables of data. At the end of the tables, i want to add a new button that can re-run the macro.

    The number of fields tracked is variable, so I have the macro select a cell two rows down and do selection.activesheets.button.add. At this point, if I don't know what the button number of the new button will be, how can I select the button to assign interior text, and assign a macro to it?

    Thanks!
    Slothboi

  2. #2
    Hi

    Try something like


    [VBA]
    Set NewButton = ActiveSheet.Buttons.Add(ActiveCell.Top, ActiveCell.Width, ActiveCell.Left, ActiveCell.Width)
    NewButton.Characters.Text = "MyText"
    NewButton.OnAction = "MyMacro"
    [/VBA]

    HTH

    Tony

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Would you consider using a floating toolbar to do this instead of the problems your up against with adding so many buttons and linking code.

    If so check out this thread(post #9 specifically)
    http://www.vbaexpress.com/forum/showthread.php?t=10994

    instead of using them in a sub you can use them in workbook open to create and before close to delete the menu
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Newbie
    Joined
    Dec 2006
    Posts
    4
    Location
    Thanks for the excellent suggestions. Both solutions work, but I am going forward with the toolbar solution. It is a more elegant implementation for what I want to do.

    Thanks again!

Posting Permissions

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