Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default private sub- which procedure called it


When i run a macro that changes a cell the code below is run.
What i need to know is which procedure caused the code below to be called.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

which macro procedure has called this routine ?

.....run code depending on which procedure has called this sub routine

End sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default private sub- which procedure called it

There is no built-in way to determine what procedure called
another. The only way would be to create a public variable, put
the caller's name in that variable, and read that variable in the
routine.

[in module1]
Public WhoCalled As New Collection

Sub AAA()
WhoCalled.Add "AAA"
' more code
End Sub

[in ThisWorkbook]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CalledBy As String
CalledBy = WhoCalled(WhoCalled.Count)
Select Case CalledBy
Case "AAA"
' do something
Case "BBB"
' do something else
Case ....
End Select

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sunil" wrote in message
...

When i run a macro that changes a cell the code below is run.
What i need to know is which procedure caused the code below to
be called.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

which macro procedure has called this routine ?

....run code depending on which procedure has called this sub
routine

End sub





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default private sub- which procedure called it

Small revision.....

Change

CalledBy = WhoCalled(WhoCalled.Count)
' to
CalledBy = WhoCalled(WhoCalled.Count)
WhoCalled.Remove WhoCalled.Count


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
There is no built-in way to determine what procedure called
another. The only way would be to create a public variable,
put the caller's name in that variable, and read that variable
in the routine.

[in module1]
Public WhoCalled As New Collection

Sub AAA()
WhoCalled.Add "AAA"
' more code
End Sub

[in ThisWorkbook]
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CalledBy As String
CalledBy = WhoCalled(WhoCalled.Count)
Select Case CalledBy
Case "AAA"
' do something
Case "BBB"
' do something else
Case ....
End Select

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sunil" wrote in message
...

When i run a macro that changes a cell the code below is run.
What i need to know is which procedure caused the code below
to be called.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

which macro procedure has called this routine ?

....run code depending on which procedure has called this sub
routine

End sub







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Sub - Called from Userform pallaver Excel Discussion (Misc queries) 3 July 15th 08 08:41 AM
How can Oracle DB Stored procedure be called in MS Excel? Amol Excel Discussion (Misc queries) 1 January 7th 07 10:05 AM
re : Possible to run private sub macros by writing another private ddiicc Excel Programming 5 August 26th 05 04:49 AM
Opening a UserForm causes a crash in the Exit procedure (Which is never called) Brent McIntyre Excel Programming 0 May 12th 04 12:37 PM
Public subroutine called from a private sub Neil Bhandar[_2_] Excel Programming 1 January 15th 04 10:23 PM


All times are GMT +1. The time now is 11:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"