+ Reply to Thread
Results 1 to 4 of 4

Calling a macro in an Add-in from a different workbook?

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Calling a macro in an Add-in from a different workbook?

    I’ve created a custom tab to modify my Ribbon in an Excel Add-in. It includes a group with a custom toggle button that disables/enables Events when clicked. The basic initiating code behind the custom toggle button came primarily from Ron de Bruin’s website and is shown below. Clicking the button on my custom ribbon tab triggers it.
    Is it possible to either call this macro from another workbook or use VBA to “click” it programmatically? I've tried the former without success and cannot find an answer to the latter. Thanks for reading.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Calling a macro in an Add-in from a different workbook?

    You could move all that code into a separate public routine and call it from the event. You should then be able to call from other workbook but I'm not sure the objects will be available when called from there.

    Why would you be calling the add-in from other workbook?
    Can you describe the use case scenario.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Calling a macro in an Add-in from a different workbook?

    The existing custom toggle makes it easy for me to both turn off Events and visually see if they are currently off or not – see the over/under pictures of my Ribbon when the button is clicked below. Yesterday, I was working on a macro that erred out, after the line

    Please Login or Register  to view this content.
    When I used my ribbon button to re-enable events, it reversed the orange highlight in the picture from highlighting it when it was off, to highlighting when it was on – see the second picture.
    That made me think it would be handy to use the custom toggle button as a primary Events status indicator and not just a switch – so that I could always tell when Events were disabled. Rather than using “Application.EnableEvents = False” in my code, if I could trigger the Ribbon code using something like:

    Please Login or Register  to view this content.
    But I haven’t been able to make it work. I’m researching your “public” comment, but at the moment I’m not completely sure what I would need to do, although that does make the error I’m getting make more sense – third picture below.

    Let me know if you have any questions. Thanks for your help.
    Attached Images Attached Images

  4. #4
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Calling a macro in an Add-in from a different workbook?

    I have continued working on this problem as and found this solution in a different Excelforum query
    Please Login or Register  to view this content.
    This solution involved calling a function from an add-in and can be found here. https://www.excelforum.com/excel-pro...-workbook.html

    I tried modifying the above solution as follows.
    Please Login or Register  to view this content.
    The first example above works, triggering a macro in my custom ribbon add-in - so the references and syntax appear correct. The second example attempts to trigger the desired custom ribbon macro shown above, but throws an error that an argument is not optional. The third example attempts to call the same macro with arguments as in the Add-in which works when the specific Ribbon button is pressed. That one gives me a 1004 error.
    I’m not sure what I need to do to make the macro work. Anyone have any suggestions? Thanks.

+ 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] Calling macro from another workbook
    By LAVA2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2018, 02:14 PM
  2. [SOLVED] Calling macro from another workbook
    By garveyarmy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-18-2017, 07:19 AM
  3. Manipulating ActiveWorkbook when calling macro from Personal Macro Workbook
    By 146considerations in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-05-2017, 12:16 AM
  4. Error when calling a 'sheet macro' inside a workbook wide macro
    By Rhino_dance in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2016, 03:46 PM
  5. calling an event macro from a different workbook
    By cwchan220 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-25-2014, 10:32 AM
  6. Calling macro in another workbook
    By scabral in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2009, 02:03 PM
  7. Calling Macro From Different Workbook
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-23-2008, 07:03 PM

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