Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default class module in a xla file

Hi to all

I have a xla file. It should share functions which are common to 2 other excel files
But the classes of these 2 files are also the same, so I integrated a class module in my xla file
And now, my 2 files can view the class (I added a reference to this xla file) but impossible to do something with that
Here is my code :
' module which have access to the xla class (named "toto")
Sub test(
Dim X As tot
X.Init ("toto"
End Su

' Function in my class (named "toto") of my xla file
Sub test(
Dim X As tot
X.Init ("toto"
End Su

What's wrong with that, I can't also add a word 'new' to my 'normal' module
Thks a lot for your answer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default class module in a xla file

Isabelle,

You can't create objects in one workbook that are based on
classes on another workbook or add-in. You can declare objects
of that type, but you can't create an instance of that object
(using the New keyword).

First, open your addin in the VBA editor and go to the Tools menu
and choose VBA Project Properties. In that dialog, give the
project a unique name, e.g., MyProj. Then, select the class
module in that project, press F4 for the Properties dialog, and
change the Instancing property from Private to
PublicNotCreatable. Then, in a standard code module of the
add-in, create a function like

Public Function GetMyClass() As MyClass
Set GetMyClass = New MyClass
End Function

where MyClass is the name of the class module.

Then, open the workbook in the VBA Editor. Go to the Tools menu,
choose References, and put a check next to MyProj, or whatever
you named the add-in project. Then, in a standard module in the
workbook's project, declare a variable of the MyClass and use the
function GetMyClass to initialize it to a new instance of
MyClass. E.g.,

Dim MC As MyProj.MyClass
Set MC = MyProj.GetMyClass()


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"isabelle" wrote in message
...
Hi to all,

I have a xla file. It should share functions which are common

to 2 other excel files.
But the classes of these 2 files are also the same, so I

integrated a class module in my xla file.
And now, my 2 files can view the class (I added a reference to

this xla file) but impossible to do something with that.
Here is my code :
' module which have access to the xla class (named "toto") :
Sub test()
Dim X As toto
X.Init ("toto")
End Sub

' Function in my class (named "toto") of my xla file:
Sub test()
Dim X As toto
X.Init ("toto")
End Sub

What's wrong with that, I can't also add a word 'new' to my

'normal' module.
Thks a lot for your answer



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default class module in a xla file

I believe you would need to have a procedure in your xla that creates and
instance of the class toto and returns a reference to it. You would then
call that procedure from the code in your spreadsheet to access the instance
of the class.

--
Regards,
Tom Ogilvy

"isabelle" wrote in message
...
Hi to all,

I have a xla file. It should share functions which are common to 2 other

excel files.
But the classes of these 2 files are also the same, so I integrated a

class module in my xla file.
And now, my 2 files can view the class (I added a reference to this xla

file) but impossible to do something with that.
Here is my code :
' module which have access to the xla class (named "toto") :
Sub test()
Dim X As toto
X.Init ("toto")
End Sub

' Function in my class (named "toto") of my xla file:
Sub test()
Dim X As toto
X.Init ("toto")
End Sub

What's wrong with that, I can't also add a word 'new' to my 'normal'

module.
Thks a lot for your answer



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default class module in a xla file - thanks !

Thanks Chip & Tom,

I have tried your solution and it works perfect

Best regards

Isabelle
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
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Class module Mark[_36_] Excel Programming 2 February 17th 04 03:14 PM
Class Module query Darren Hill[_2_] Excel Programming 2 January 23rd 04 04:23 PM
Class module David Excel Programming 4 December 31st 03 01:58 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


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