+ Reply to Thread
Results 1 to 3 of 3

How to call a sheet-specific macro

  1. #1
    Forum Contributor
    Join Date
    04-14-2008
    Location
    Fort Collins, Co
    MS-Off Ver
    2016
    Posts
    107

    Question How to call a sheet-specific macro

    Hi.
    I have a sheet that uses a plugin to run a SQL query into excel. In that sheet is a button attached to a sub called 'update_now'
    I want to run 'update_now' from another sheet, but just assigning the button to the macro doesn't work, because the macro is looking in the current sheet.

    I think the easiest thing for me to do would be to make another macro that "calls" that sheet-specific macro.

    Any help? I've tried Application.Run ("'update_now") and it doesn't work.

    ADDITIONAL INFO: Not sure if it matters, but the code for that macro is in its own VBA Project called 'dataplug98.xla' and it's own module called 'dataplug_code'

    EDIT 2: Application.Run "'YourAdd-in.xla'!YourSubName" - works but then I get the error because it's trying to run from the sheet I'm on instead of the sheet that the macro should run from... I may need to edit the code for the add-in to point to a specific sheet?
    Last edited by 4am; 07-23-2013 at 01:41 PM.
    Is That Your Spreadsheet Or Did Your Database Just Throw Up?


  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: How to call a sheet-specific macro

    put the sub update_now in a module in modules, not in sheet, then assign it to button
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: How to call a sheet-specific macro

    You can copy and past the macro to the module for the sheet you're trying to run the code on, and change all the sheet references to the correct sheet. Or you can copy the macro to the workbook module and change the sheet references to ActiveSheet.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

+ 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] Call a specific macro by selecting different cells
    By ska87RA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2013, 09:14 AM
  2. [SOLVED] Macro to call data from a specified file in the sheet
    By tpayne89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 09:28 AM
  3. Call macro (Sheet 1) from any change in sheet 2
    By mark02 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2012, 10:29 PM
  4. Call macro if specific text is within listbox
    By EthanM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2011, 12:00 AM
  5. Macro to call sheet number instead of name
    By Alexis2891 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-13-2007, 07:57 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