Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Question Regarding Name Function

It should work as you suggested, but perhaps the author was trying to
illustrate some point about making the function perform in both arenas where
there would be a difference.

--
Regards,
Tom Ogilvy

"Dustin Schofield" wrote in message
...
I am new to excel programming and so am using books in an effort to learn.
Up until now, I have attempted to completely understand presented code
before moving on. I have come across one example that is giving me a
difficult time, however.

It is a function that is apparently designed to run both as a worksheet
function and as a VBA callable procedure. It's purpose is to simply check
to see whether a name exists in a workbook and return a true or false
expression.

The code is as follows:


Function IsNameInWorkbook(stName As String) As Boolean

Dim X As String
Dim Rng As Range

Application.Volatile
On Error Resume Next

Set Rng = Application.Caller
Err.Clear

If Rng Is Nothing Then
X = ActiveWorkbook.Names(stName).Name
Else
X = Rng.Parent.Parent.Names(stName).Name
End If

If Err.Number = 0 Then IsNameInWorkbook = True

End Function


I follow this code for the most part but am wondering why certain elements
are necessary. My question is this: Why is a check performed to ascertain
where the function was called? Would not the code below work just as
effectively in both situations (that is - from a worksheet or VBA
procedure)?


Function IsNameInWorkbook(stName As String) As Boolean

Dim X As String

Application.Volatile
On Error Resume Next

X = ActiveWorkbook.Names(stName).Name

If Err.Number = 0 Then IsNameInWorkbook = True

End Function


Any help or thoughts would be greatly appreciated,

Thanx

Dustin




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
If Function Question?? Schwimms Excel Discussion (Misc queries) 3 July 31st 07 09:17 PM
If Function Question Schwimms Excel Discussion (Misc queries) 7 July 31st 07 06:36 PM
Function question: [email protected] Excel Worksheet Functions 5 March 26th 07 09:26 PM
IF function Question Machineman Excel Worksheet Functions 5 November 26th 06 11:48 PM
Function question Dale Rosenthal New Users to Excel 2 January 25th 05 02:10 PM


All times are GMT +1. The time now is 11:28 AM.

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

About Us

"It's about Microsoft Excel"