+ Reply to Thread
Results 1 to 14 of 14

Store Name Of The Calling Procedure In A Variable

  1. #1
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Store Name Of The Calling Procedure In A Variable

    Does any one know how to store name of the calling procedure in a variable?

    I have many procedures that make the Pivot Table Change, however I want to access the code of Worksheet_PivotTableUpdate only when a certain Procedure is run.

    Can anyone help?
    Cheers!
    Deep Dave

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Store Name Of The Calling Procedure In A Variable

    I found this link which almost confirms ,my thoughts too
    http://www.mrexcel.com/forum/excel-q...lications.html
    You would have to access the VBE environment.
    My idea would be to add a public variable name ProcedureName and have the first line of code in each procedure set the variable equal to the procedure's name.
    Then you can use this value to check on it.
    Maybe an idea?
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Store Name Of The Calling Procedure In A Variable

    Hi,

    Thank you for the reply.. I had already gone through that link before posting.. Thank you for the time anyways..

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

    Re: Store Name Of The Calling Procedure In A Variable

    Other procedures may disable events before changing pivot table.
    • 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

  5. #5
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Store Name Of The Calling Procedure In A Variable

    Ill explain a bit more, maybe it will help..

    I have Just 1 Pivot Table, and 10 macros that generate different Pivot Reports.. So Basically all those 10 macros access Worksheet_PivotTableUpdate event.

    Now, Consider I have few lines of code in the Worksheet_PivotTableUpdate section. I want Worksheet_PivotTableUpdate to only execute the code for only 1 particular macro of the 10. I tried setting flags, using global variables, but I still run into problems..
    Last edited by NeedForExcel; 01-06-2016 at 05:09 AM.

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

    Re: Store Name Of The Calling Procedure In A Variable

    What problem do you have setting flag? Why do you not run code you wish directly from macro and not from event or use withevents variable?

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Store Name Of The Calling Procedure In A Variable

    Actually the problem is, I am using Slicers..

    Please Login or Register  to view this content.
    My requirement is simple.. When The above code is executed and the Pivot Updates the below code is called. When I execute the Sub WhoElseGotIt I want the red line to be executed, but not when a slicer button updates the Pivot Table. The slicer also triggers the Pivot Update event indirectly, and hence PT.ClearTable clears the table, which spoils the remaining procedure..

    Please Login or Register  to view this content.
    So In short, I want the PT.ClearTable line to be executed only when the Pivot Table is updated by a Sub and not by the slicer..
    Last edited by NeedForExcel; 01-06-2016 at 05:28 AM.

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

    Re: Store Name Of The Calling Procedure In A Variable

    First macro will set variable. Called macro will check variable and cleartable if desired and then will clear variable. Do you have problem with this?

  9. #9
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Store Name Of The Calling Procedure In A Variable

    Maybe I have confused myself and hence confused you.. Let me simplify.

    Sub WhoElseGotIt sets up the Pivot Table and calls a procedure AddSlicerForProductWhoElseGotIt which sets up the slicer.

    As soon as the Pivot Updates, the below procedure is called.

    Please Login or Register  to view this content.
    Since, the Sub WhoElseGotItReverse (This sub is called on Pivot Update) has a Line to clear the Pivot Table, it causes the problem.. Because, even on slicer update, the macro gets triggered.. Hope I make sense..

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

    Re: Store Name Of The Calling Procedure In A Variable

    So:
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.
    and also:
    Please Login or Register  to view this content.
    or I did not understand you?

  11. #11
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Store Name Of The Calling Procedure In A Variable

    Thank you for the reply.. That isn't working because, even on slicer click the Pivot Table Updates, and calls the below event

    Please Login or Register  to view this content.
    Which in turn calls Sub WhoElseGotItReverse(UserArray) which executes the line PT.ClearTable before setting bClearTable = False

    But I guess this solves the initial problem

    Please Login or Register  to view this content.
    But I ran into another problem.. I guess, It can't be done this way it seems after all.. I just wish even Slicers had events associated with them..
    Last edited by NeedForExcel; 01-07-2016 at 12:06 AM.

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Store Name Of The Calling Procedure In A Variable

    Maybe there are events to check if the pivot table changes?

  13. #13
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Store Name Of The Calling Procedure In A Variable

    That is exactly the I am using - Worksheet_PivotTableUpdate

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

    Re: Store Name Of The Calling Procedure In A Variable

    I do not understand this. If first macro will not run bClearTable will be False and clear table code will not run. Please show workbook with problem.

+ 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. Calling Procedure or Function inside another Procedure - variables problem
    By Rudo123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-22-2015, 03:12 PM
  2. [SOLVED] Problem with calling another macro (Error 450 and " Expected variable or procedure")
    By Roxner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-07-2013, 04:59 AM
  3. Replies: 0
    Last Post: 10-02-2012, 03:06 PM
  4. Name of calling procedure
    By ajaykgarg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2011, 04:02 PM
  5. How to Call a Store Procedure!!!
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2006, 06:10 AM
  6. How to pass a variable from Form back to calling procedure
    By John in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2005, 11:05 AM
  7. [SOLVED] Calling sub procedure
    By Yossi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2005, 09:05 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