The reason you can't call a method (sub or function member of a class)
directly is because the object defined by the class doesn't exist until you
create it with the NEW keyword (or CreateObject - but usually you should use
NEW).

 

It doesn't exist for a reason - each time you use the NEW keyword you create
a unique entity - that object is an individual., and the variables, methods,
properties, etc. of that object have their own scope.  a CLASS is a "class
of object".  If you imagine a class called PERSON, it might have a property
called "First Name" and another called "Last Name".  If you could access
those properties without "instantiating a class" (creating an instance of
the class, i.e. a new object based on it) every PERSON in the world would
have to have the same name (and everything else about them would have to be
the same, and they would have to behave the same.).  WORKSHEET is an example
of a built-in class.  You can't refer to it's properties and methods unless
you refer to a specific worksheet object.  Excel automatically creates
WORKSHEET objects worksheets are added to the workbook, and disposes of them
when they're removed.

 

You can find some tutorials for classes online, such as:

http://www.cimaware.com/resources/article_39.html

http://www.cpearson.com/excel/classes.aspx

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of Matt
Sent: Wednesday, April 11, 2012 6:21 AM
To: excel-macros@googlegroups.com
Subject: Re: $$Excel-Macros$$ Call a Function

 

Yes, I moved it to another module and I believe I had an older copy of that
code in a different module as well and that was a problem too.

 

I've been trying to understand classes (I know they create objects) and
their use, thats why I originally used the "class module" though.
On Tuesday, April 10, 2012 9:53:09 PM UTC-4, Asa R. wrote:

Hi Matt,

Glad to help.  What was your solution?  Moving the functions to a standard
module instead of the class module?

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of Matt
Sent: Tuesday, April 10, 2012 6:03 PM
To: excel-macros@googlegroups.com
Subject: Re: $$Excel-Macros$$ Call a Function

 

Thanks Asa. Your advice helped! I thought I tried it before but I guess I
missed something and it works now.

 

Tx again'

 

Matt

On Thursday, April 5, 2012 3:27:51 PM UTC-4, tag wrote:

please see...


Sub or Function not defined (Visual Basic)  


A Sub or Function must be defined in order to be called. Possible causes of
this error include:

.        Misspelling the procedure name.

.        Trying to call a procedure from another project without explicitly
adding a reference to that project in the References dialog box.

.        Specifying a procedure that is not visible to the calling
procedure.

.        Declaring a Windows dynamic-link library (DLL) routine or Macintosh
code-resource routine that is not in the specified library or code resource.


To correct this error


1.     Make sure that the procedure name is spelled correctly.

2.     Find the name of the project containing the procedure you want to
call in the References dialog box. If it does not appear, click the Browse
button to search for it. Select the check box to the left of the project
name, and then click OK.

3.     Check the name of the routine. 

2012/4/5 ChilExcel <chilexcel...@gmail.com>

Please attach example, to better understand

 

 

Chilexcel

2012/4/5 Matt <moni...@gmail.com>

Hello, I'm trying to call a public function in one module from another Sub
procedure in another module and it won't call the the function. I get an
error that says.."sub function not defined" But when I include the function
within the same module, my code works...

 

I can't seem to find the answer online...

 

 

What is the problem?

Thanks again for your help.

 

Matt

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 
----------------------------------------------------------------------------
--------------------------
To post to this group, send email to excel-macros@googlegroups.com





-- 

Visita ; http://sites.google.com/site/chilexcel/Home

Visita ; http://www.youtube.com/user/timextag41

 




-- 

Visita ; http://sites.google.com/site/chilexcel/Home

Visita ; http://www.youtube.com/user/timextag41

 

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 
----------------------------------------------------------------------------
--------------------------
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 
----------------------------------------------------------------------------
--------------------------
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

Reply via email to