+ Reply to Thread
Results 1 to 2 of 2

Assigning buttons to VBA modules using VBA code

  1. #1
    Registered User
    Join Date
    01-08-2016
    Location
    Johannesburg, South Africa
    MS-Off Ver
    MS Office Professional Plus 2013
    Posts
    1

    Assigning buttons to VBA modules using VBA code

    Hi

    Have been struggling with the below, would really appreciate some advice!

    I have a template workbook (call it "templatebook") that generates a new workbook ("newbook") with various sheets based on templates and data in templatebook using vba. There are two vba modules in templatebook that get exported to newbook. Once the two macros are in newbook I'm then trying to assign them to buttons on one of the sheets using:

    Newbook.Activate
    ActiveSheet.Shapes.Range(Array("Button 1")).Select
    Selection.OnAction = "datarun"
    ActiveSheet.Shapes.Range(Array("Button 2")).Select
    Selection.OnAction = "dataclear"

    The problem I'm having is that the buttons in the sheet in Newbook are being assigned by the above code to the relevant modules in the original templatebook and not to the modules in newbook. This means that to run the macros in newbook then templatebook has to open which is obviously what I don't want.

    Could it be an object issue where I'm not being specific enough on which modules to assign the buttons to, and then because of this it assigns them to the modules in templatebook?

    Thanks
    Darren

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Assigning buttons to VBA modules using VBA code

    Did you try with:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Assigning macro to Buttons in a Sheet
    By Howardiser in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-18-2012, 10:08 PM
  2. Assigning macros to buttons on all worksheets
    By The Skipper in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-23-2012, 05:26 AM
  3. Assigning functions to buttons
    By Vytfla in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 06-17-2011, 10:52 AM
  4. assigning code to buttons
    By crazyhick in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-28-2010, 08:02 AM
  5. assigning code to buttons
    By crazyhick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2010, 06:36 AM
  6. keep on assigning macro to buttons
    By bery1_16 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2006, 02:34 PM
  7. Assigning Macros to Buttons
    By Christine in forum Excel General
    Replies: 1
    Last Post: 05-11-2006, 04:45 PM
  8. [SOLVED] assigning macros to buttons or autoshapes
    By John of the new year in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM

Tags for this Thread

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