Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default VBA:: determine if UDF exists?

In a workbook w/ multiple sheets, w/ a loop thus ...

dim mySheet as worksheet
For Each mySheet In ActiveWorkbook.Sheets
mySheet.Activate
Worksheets(mySheet.Name).myUDF
Next mySheet

Can I test whether 'myUDF' exists in each mySheet?

I can solve my problem using 'On Error GoTo ...', or by creating a stub
in each sheet; I'm just wondering if there's a more direct way to get
there.

Thanks,
George
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA:: determine if UDF exists?

I think you'd have to know something about what the UDF needs passed to it, too.

I put this in a few worksheet modules:

Option Explicit
Function myUDF(SomeVar As Variant) As Variant
'do lots of work here
myUDF = 999
End Function


Then I could use something like this to look for it:

Option Explicit
Sub testme()
Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
On Error Resume Next
Application.Run wks.CodeName & ".myUDF", "aa"
If Err.Number < 0 Then
MsgBox "not found in: " & wks.CodeName & "--" & wks.Name
Err.Clear
Else
MsgBox "Found in: " & wks.CodeName & "--" & wks.Name
End If
On Error GoTo 0
Next wks
End Sub

But for the most part, if I'm gonna use the same UDF in various spots, I'll put
it in a general module and just have the other code call that single UDF.



George wrote:

In a workbook w/ multiple sheets, w/ a loop thus ...

dim mySheet as worksheet
For Each mySheet In ActiveWorkbook.Sheets
mySheet.Activate
Worksheets(mySheet.Name).myUDF
Next mySheet

Can I test whether 'myUDF' exists in each mySheet?

I can solve my problem using 'On Error GoTo ...', or by creating a stub
in each sheet; I'm just wondering if there's a more direct way to get
there.

Thanks,
George


--

Dave Peterson
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
Determine if a File Exists Connie Excel Discussion (Misc queries) 1 November 8th 06 09:11 AM
File Exists Mike McLellan Excel Discussion (Misc queries) 2 May 4th 06 09:20 AM
Need help with a function I'm not sure exists Cervantes Excel Worksheet Functions 7 August 16th 05 06:38 AM
Determine if Value in column A exists in Column B TJKarakowski Excel Discussion (Misc queries) 3 July 19th 05 06:27 PM
Sheet name already exists eddie_zoom Excel Discussion (Misc queries) 1 March 11th 05 02:53 PM


All times are GMT +1. The time now is 07:28 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"