+ Reply to Thread
Results 1 to 5 of 5

Sheet UDF from VBA Class

  1. #1
    Registered User
    Join Date
    08-31-2015
    Location
    UK
    MS-Off Ver
    2007/2010
    Posts
    22

    Question Sheet UDF from VBA Class

    Hi,

    Does anybody know how I can go about calling a Function of a VBA Class (Not from a module) as a User Defined Function in an excel sheet?

    Thanks.

    Ed

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Sheet UDF from VBA Class

    You can not use the function directly you would need to create an object and re reference that. It would also require a wrapper function in a module to do it.

    Class1 code
    Please Login or Register  to view this content.
    module code
    Please Login or Register  to view this content.
    reference from sheet cell

    =ClassWrapper_Username()

    It would be better to copy the function to a module.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-31-2015
    Location
    UK
    MS-Off Ver
    2007/2010
    Posts
    22

    Re: Sheet UDF from VBA Class

    Cheers. Can I add... Is there a way to have Functions at Module level but prevent them from being called as a UDF (without having to place the functions into code behind sheet). I guess it is possible to make them invisible to the functions listing but user could still type in manually the function name...?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Sheet UDF from VBA Class

    Please Login or Register  to view this content.
    Option Private Module, will exclude the function name from intellisense if typed in cell.
    Checking application.caller can be used to restricted action of function

  5. #5
    Registered User
    Join Date
    08-31-2015
    Location
    UK
    MS-Off Ver
    2007/2010
    Posts
    22

    Re: Sheet UDF from VBA Class

    Cheers, Andy!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Importing .BAS to Sheet Object... NOT Class Module?
    By crabby09 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2014, 10:54 AM
  2. [SOLVED] printing a sheet for a specific class? or the whole lot?
    By salimnore in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-11-2014, 11:18 AM
  3. [SOLVED] Class Newbie question #2 - Check if Class already loaded/set?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-16-2014, 06:59 PM
  4. Simple Class schedule for 5 students into one sheet?
    By Shaanujaanu in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 01-29-2014, 07:32 AM
  5. class foactory cannt supply requested class
    By rakeshkaduskar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2012, 02:00 PM
  6. Replies: 0
    Last Post: 07-08-2012, 11:12 AM
  7. [SOLVED] ComboBox class .AddItem filled in class module
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-03-2012, 05:48 AM

Tags for this Thread

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