+ Reply to Thread
Results 1 to 3 of 3

Determine if UDF Exists

  1. #1
    Registered User
    Join Date
    02-09-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Determine if UDF Exists

    I need code that will determine if a user defined function exists in a VBA project.

    Assume that the workbook containing the project is already open and that the user defined function is named "Myfunction". I think the code probably should loop through the VBProject components somehow, identify the user defined functions, and if "Myfunction" is found, then do something, like display a message box.

    I need this because I am adding the function by programmatically inserting code by ".bas" to files in a directory that may or may not already have the function defined. If it already exists in the file, the function is double defined and does not work.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Determine if UDF Exists

    You could perhaps use Evaluate to test for #NAME? errors

    Please Login or Register  to view this content.
    If you change UDFName to UDFName2 you will note it flags the UDF as missing (via the Debug)
    Other errors resulting from the UDF (wrong types etc) are ignored

  3. #3
    Registered User
    Join Date
    02-09-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Determine if UDF Exists

    This is great! It's very elegant - I thought I would probably have to search through each sheet in each workbook, looking for error messages, and determining if the UDF in question was used (and even that would not tell me if the function existed).

    Many, many thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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