Xavier N
Guest
|
I try to access excel application in a standard module using the property ExcelApp of AddinModule but it send me the error message 'ExcelApp' is not a member of 'AddinExpress.MSO.ADXAddinModule...(It doesn't work in any project...)
Sub Procedure
...
Dim xlApp As Excel.Application = AddinModule.CurrentInstance.ExcelApp
End sub
(In the AddinModule: 'Dim xlApp As Excel.Application = Me.ExcelApp' is working).
If you have any idea or suggestions ?
Regards. Xavier |
|
Eugene Astafiev
Guest
|
Hi Xavier,
Sorry, I don't quite understand you. Could you please send a sample add-in project to the support e-mail address (see readme.txt for details)?
FYI Please note that you use an old build of Add-in Express 2010. You can download a new one from http://www.add-in-express.com/downloads/adxnet.php. Please don't forget to replace the adxloader.dll in the Loader folder of your project with a new one (see the Redistributables folder). |
|
Eugene Astafiev
Guest
|
Hi Xavier,
Please try to convert an object which is returned from the CurrentInstance property to your add-in module type:
CType (ADXAddinModule.CurrentInstance, AddinModule)
Does it help? |
|
Xavier N
Guest
|
Hi Eugene,
Unfortunately the CType conversion doesn't work but i solved the problem:
Module Module1
Sub testExcelApp() '
Dim xlApp As Excel.Application
'Method1: This code does not work and give the error message 'ExcelApp' is not a member of 'AddinExpress.MSO.ADXAddinModule..
xlApp = AddinModule.CurrentInstance.ExcelApp()
'Method2: This code works and adxComAddin expose ExcelApp property
Dim adxComAddin As AddinModule = AddinModule.CurrentInstance
xlApp = adxComAddin.ExcelApp
End Sub
End Module
I'm coming from VBA so i don't master VB.net object oriented code really well but if anyone can give me an explaination why Method1 fail and why method2 succeed, i'll be glad of it..
Thanks Eugene
Regards. Xavier |
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Hi Xavier,
It looks like you have Option Strict Off.
AddinModule.CurrentInstance - returns AddinExpress.MSO.ADXAddinModule which doesn't contain ExcelApp; whence your first method doesn't work
Dim adxComAddin As AddinModule = AddinModule.CurrentInstance
Here, the result of AddinModule.CurrentInstance (and you already know that it is AddinExpress.MSO.ADXAddinModule) is implicitely casted to {your project}.AddinModule and this is why the second method works. If you were using Option Strict On, you would require to perform that cast explicitely, that is:
Dim adxComAddin As AddinModule = CType(AddinModule.CurrentInstance, AddinModule)
or
Dim adxComAddin As MyAddin1.AddinModule = CType(AddinModule.CurrentInstance, MyAddin1.AddinModule)
The second variant highlights that AddinModule from "CType(AddinModule.CurrentInstance..." is probably a property of the object in which your code runs, say, a property page. If so, here's the third variant:
Dim adxComAddin As MyAddin1.AddinModule = CType(Me.AddinModule.CurrentInstance, MyAddin1.AddinModule)
Two scenarios are possible:
- you continue to use Option Strict Off
- you start using Option Strict On and perform all casts explicitely
This is up to you, of course. I was a VBer in my previous life but now I prefer using C#; whenever I use VB.NET, I use explicit casts because I believe it helps me to control the things better.
God luck!
Andrei Smolin
Add-in Express Team Leader |
|
Xavier N
Guest
|
Thanks for your explaination Andrei,
And for taking time to explain the subtilities of accessing AddinModule. I still need to enhance my background .net kwnowledge...
I'll follow your advice using Option Strict On
Regards. Xavier |
|