+ Reply to Thread
Results 1 to 3 of 3

Asigning VBA modules on the fly...

  1. #1
    Registered User
    Join Date
    09-24-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003 & Excel 2007
    Posts
    1

    Asigning VBA modules on the fly...

    Hi,

    I have a problem.

    Using VB I want to insert a button into a worksheet (either a form or ActiveX button) and assign it to a specific VB module.

    So, loop 5 times and each pass of the loop insert a button and then assign the executable for the button-click to, say, a module called RunMe1, RunMe2, RunMe3, etc. The modules name will actually be constant, what I cannot do is access the buttons properties to tell it which module to assign to the individual buttons.

    I can loop down and insert the buttons using a template button, but after each paste it loses the reference to the module. Anyone any thoughts...

    I'm using Excel 2003 and 2007.

    Thanks,

    Errol

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Asigning VBA modules on the fly...

    See the attached Excel 2003 file that creates a button
    and has code ready and waiting for the new button.
    This may not be the best solution, if it can be done
    at all, but I gave it a try.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by xLJer; 09-25-2012 at 12:16 AM.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Asigning VBA modules on the fly...

    if you use buttons.add it returns a button object (forms not activex-avoid activex on sheets if you can) and you can set its onaction property to the name of the macro (not module) you want it to run
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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