View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Using same Class in several projects


It's impossible to suggest a preference as any would depend on the overall
scenario, taking perhaps many factors into consideration. Some general
comments:~

Application.Run
Pro: no need to set and manage references
Con: significantly less efficient than calling direct (probably only
relevant in time sensitive long loops).

Reference
Pro: Can call directly functions in normal modules and existing object
modules (sheet & thisworkbook modules but not ordinary Class modules). You
get intellisense.
Con: If a reference goes 'missing' problems will occur. More work to
establish the references in the first place.

With both the above you'd call a 'helper' function in a main module to
manage the class, accept input arguments and return resolute or create your
report, if that's the objective.

Add/removeclass programmatically
Two approaches. A main wb updates all the others when it knows there's a new
class module to be updated in the 20 wb's. Or each wb updates itself. In the
open event you ask - in theory yes but doubt you'd want to do that each time
(or does code in the class change that often!. Maybe the open event could
first check by some means if there the class module need replacing before
doing so.

Regards,
Peter T

"WhytheQ" wrote in message
...
Thanks for the help on this thread.

(In this particular situation Option 2 isn't possible as each workbook
does different things - the class just creates a report from each
wb...clMngmtReport....and each report is run at a different time of
day)

Have you got a personal preference Peter ?
1.Application.run
2.Reference
3.Adding/removing class programmatically - this could be done on
auto_open?

What is a "a helper function in the class wb."?

J




On 15 Apr, 17:46, "Peter T" <peter_t@discussions wrote:
Looks like you've got three options

1. Keep the class in one wb and call in from your other wb's.
Application.run or set a reference in all 20 wb's. Either way you'll

need a
helper function in the class wb.

2. Maybe you only need code in one wb which can process all the other 20
wb's. Those would be empty of code, except possibly 20 open events to

open
the main code wb if/as required.

3. You suggest manually updating new code in the 20 wb's is tedious.
Programmatically you can update code in the 20 wb's, or replace entire

old
module with new module. In effect 'Remove' old (class) module, add new
(class) module from file.

Regards,
Peter T

"WhytheQ" wrote in message


...



Hello All,


Another question in connection with class modules:


- clCommon is used in 20 workbooks.
- clCommon quite often has additional code added.


How do I avoid having to go through all 20 workbooks to change the
code in clCommon ?


Any help appreciated,
Jason.- Hide quoted text -


- Show quoted text -