+ Reply to Thread
Results 1 to 3 of 3

Determining which subroutine is calling another subroutine?

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    Ontario
    MS-Off Ver
    Excel 2021
    Posts
    35

    Determining which subroutine is calling another subroutine?

    Suppose I have two subroutines - Sub1 and Sub2 - that both call a third subroutine - Sub3. Is there some code I can put inside Sub3 so that when it's running, it knows whether it was called by Sub1 or Sub2?

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Determining which subroutine is calling another subroutine?

    this might work

    Please Login or Register  to view this content.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,822

    Re: Determining which subroutine is calling another subroutine?

    There is no built-in way in VBA for a Sub to discover which Sub called it. The method judgeh59 describes is pretty much all you can do, although the syntax isn't correct.
    Please Login or Register  to view this content.
    However, I would like to convince you that this is a poor design practice. A Sub should have inputs, outputs, and a function to perform. It should not care who called it to perform this function. Can you provide a little more information about your code structure, and why Sub3 needs to know who called it? There might be alternatives that result in a better design.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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] Crashes when calling subroutine
    By sbe70 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-18-2015, 05:23 AM
  2. Calling Subroutine from Module
    By indrapurkay in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-16-2015, 07:08 PM
  3. Calling a Variable Subroutine
    By WayneFontes in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-27-2007, 03:47 PM
  4. Calling a Subroutine (2)
    By Configurator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2007, 06:52 PM
  5. Trouble calling subroutine
    By Configurator in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2007, 02:07 PM
  6. HELP! Calling subroutine in different workbook
    By ChrisWalker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2006, 07:32 AM
  7. Calling a subroutine in another workbook
    By mta37 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2005, 12:23 AM

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