Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Test if Function is Run from worksheet or from VBA

Is there any way I can test whether a function has been called because it is
used in a cell, or whether it is called from code?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Test if Function is Run from worksheet or from VBA

Try commenting out the function and see if you get a code error or bad
references.

Andibevan wrote:
Is there any way I can test whether a function has been called because it is
used in a cell, or whether it is called from code?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Test if Function is Run from worksheet or from VBA

Check out Application.Caller

NickHK

"Andibevan" .gbl...
Is there any way I can test whether a function has been called because it
is
used in a cell, or whether it is called from code?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Test if Function is Run from worksheet or from VBA

Something like this perhaps

Function myFunc()
Dim x
On Error Resume Next
x = Application.Caller.Address
If Err.Number = 0 Then
MsgBox "Called from Worksheet"
Else
MsgBox "Called from VBA"
End If
On Error GoTo 0
End Function



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Andibevan" wrote in message
...
Is there any way I can test whether a function has been called because it

is
used in a cell, or whether it is called from code?





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Test if Function is Run from worksheet or from VBA

One mo

if typename(application.caller) = "Range" then
'called from a cell
else
'not called from a cell
end if

(Case is important in "Range".)




Andibevan wrote:

Is there any way I can test whether a function has been called because it is
used in a cell, or whether it is called from code?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Test if Function is Run from worksheet or from VBA

Thanks for all the suggestions


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
Test cell interior color by worksheet function? Skimmer Excel Worksheet Functions 7 September 4th 07 09:40 PM
Getting corresponding test value to a MIN function Willis in crisis Excel Worksheet Functions 1 November 2nd 05 06:32 PM
Getting corresponding test value to a MIN function confused_chris Excel Programming 3 October 22nd 05 01:30 AM
Test worksheet name Petr Excel Programming 4 June 25th 04 01:57 PM
Test for Worksheet Paul Excel Programming 5 April 30th 04 10:29 PM


All times are GMT +1. The time now is 02:15 AM.

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"