Access AddinModule's static variables from UDF

Add-in Express™ Support Service
That's what is more important than anything else

Access AddinModule's static variables from UDF
 
ideaFocus




Posts: 63
Joined: 2013-07-19
Hi,

I have a static field which is being used in AddinModule and I want to access that field some in UDF to get and display some information. I tried doing it but it's giving me null, even though it's not null on the COM add in side.

Is there anyway I can access that field with it's contents.

Thanks,
Attiqe
Posted 18 Jun, 2014 11:34:52 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Attiqe,

You can get it using a public method defined in the add-in module:

ExcelApp.COMAddins.Item(strMyComAddinProgId).Object.MyPublicMethod.


Andrei Smolin
Add-in Express Team Leader
Posted 19 Jun, 2014 07:10:33 Top
ideaFocus




Posts: 63
Joined: 2013-07-19
Andrei,

ExcelApp.COMAddins.Item("MyAddin.AddinModule").Object returns COM object not AddinModule?

While waiting for your reply I started working on another way of doing it by following this article: http://www.add-in-express.com/creating-addins-blog/2011/10/11/invoke-excel-addin-xll/
sample project runs fine but when I add XLL Addin Module and UDF in my project it isn't showing up in the Excel Add-in and it's NAME error for the UDF in cell. Following is Logs:


Startup directory: C:\Users\Attiqe Ur Rehman\Source\Workspaces\PowerOutline\PowerOutline\bin\Debug\
Loader version: 7.5.4072.0
Operating System: Microsoft Windows 7 Professional Service Pack 1 (build 7601), 64-bit
Process Owner: Administrator
Command Line: "C:\Program Files\Microsoft Office\Office15\EXCEL.EXE"
Run 'As Administrator': Yes
Process Elevated: Yes
Integrity Level: High
UAC (User Account Control): Off
------------------------------------------------------------------------
19:19:02:421 2416 3244 Start.
19:19:02:421 2416 3244 Reading the registry key 'HKEY_CLASSES_ROOT\CLSID\{D94DD481-5761-4CA3-B43A-47572F0D3FC8}'
19:19:02:422 2416 3244 Success. The registry key 'HKEY_CLASSES_ROOT\CLSID\{D94DD481-5761-4CA3-B43A-47572F0D3FC8}' is closed.
19:19:02:422 2416 3244 Converting the '{4BA250A6-8BCA-46A6-982A-F340081187C3}' CLSID from string.
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Attempting to get the class object by the '{4BA250A6-8BCA-46A6-982A-F340081187C3}' CLSID.
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Creating a new instance of the add-in loader.
19:19:02:422 2416 3244 Loading mscoree.dll
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Loading the configuration from the system registry.
19:19:02:422 2416 3244 Getting the latest CLR version.
19:19:02:422 2416 3244 The latest CLR version is 'v4.0.30319'.
19:19:02:422 2416 3244 The configuration has been loaded successfully.
19:19:02:422 2416 3244 Runtime version: v4.0.30319.
19:19:02:422 2416 3244 Assembly name: PowerOutline, PublicKeyToken=521E0A50813E7CA0.
19:19:02:422 2416 3244 Class name: PowerOutline.AddinModule.
19:19:02:422 2416 3244 Registry key: CLSID\{D94DD481-5761-4CA3-B43A-47572F0D3FC8}.
19:19:02:422 2416 3244 Attempting to create a new instance of the managed add-in class: CLR - v4.0.30319
19:19:02:422 2416 3244 Loading CLR: v4.0.30319.
19:19:02:422 2416 3244 Calling CLRCreateInstance method.
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Calling GetRuntime method.
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Checking if the hosting API of .NET Framework v4.0 beta is installed.
19:19:02:422 2416 3244 The hosting API is up to date.
19:19:02:422 2416 3244 Calling GetInterface method for the CorRuntimeHost interface.
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Starting CLR...
19:19:02:422 2416 3244 Success.
19:19:02:422 2416 3244 Getting the CLR version.
19:19:02:422 2416 3244 The CLR v4.0.30319 has been initialized successfully.
19:19:02:422 2416 3244 Creating a new domain setup.
19:19:02:423 2416 3244 Success.
19:19:02:423 2416 3244 Getting the add-in directory.
19:19:02:423 2416 3244 Success. The directory is 'C:\Users\Attiqe Ur Rehman\Source\Workspaces\PowerOutline\PowerOutline\bin\Debug\'
19:19:02:423 2416 3244 The 'shadow copy' is enabled.
19:19:02:423 2416 3244 Creating a new application domain.
19:19:02:429 2416 3244 Success.
19:19:02:429 2416 3244 Creating an instance of the managed class. Assembly identity: 'PowerOutline, PublicKeyToken=521E0A50813E7CA0'
19:19:03:153 2416 3244 Success.
19:19:03:153 2416 3244 Unwrapping the managed class.
19:19:03:211 2416 3244 Success.
19:19:03:211 2416 3244 Querying the add-in extensibility.
19:19:03:211 2416 3244 Success.
19:19:03:211 2416 3244 Querying the custom task panes.
19:19:03:211 2416 3244 Success.
19:19:03:211 2416 3244 Querying the ribbon extensibility.
19:19:03:211 2416 3244 Success.
19:19:03:211 2416 3244 Querying the form regions.
19:19:03:211 2416 3244 Success.
19:19:03:211 2416 3244 Getting the dispid of the 'Dispose' method.
19:19:03:239 2416 3244 Success.
19:19:03:239 2416 3244 The managed add-in class has been created successfully.
19:20:39:064 2416 3244 Start - xlAddInManagerInfo12.
19:20:39:064 2416 3244 Creating a new instance of the XLL loader.
19:20:39:064 2416 3244 Success.
19:20:39:064 2416 3244 Getting the CLSID of the managed XLL class.
19:20:39:064 2416 3244 Success.
19:20:39:064 2416 3244 Loading the configuration from the system registry.
19:20:39:065 2416 3244 Getting the latest CLR version.
19:20:39:065 2416 3244 The latest CLR version is 'v4.0.30319'.
19:20:39:065 2416 3244 The configuration has been loaded successfully.
19:20:39:065 2416 3244 Runtime version: v4.0.30319.
19:20:39:065 2416 3244 Assembly name: PowerOutline, Version=1.0.0.3, Culture=neutral, PublicKeyToken=521e0a50813e7ca0.
19:20:39:065 2416 3244 Class name: PowerOutline.PoXllModule.
19:20:39:065 2416 3244 Registry key: CLSID\{38064809-9880-3BC2-926C-2D8215EA3ABD}.
19:20:39:065 2416 3244 Attempting to create a new instance of the managed XLL class: CLR - v4.0.30319
19:20:39:065 2416 3244 Getting the base directory for the domain.
19:20:39:065 2416 3244 Success. The directory is 'C:\Users\Attiqe Ur Rehman\Source\Workspaces\PowerOutline\PowerOutline\bin\Debug\'.
19:20:39:065 2416 3244 Opening adxloader.dll.manifest.
19:20:39:065 2416 3244 Success. The manifest is 'C:\Users\Attiqe Ur Rehman\Source\Workspaces\PowerOutline\PowerOutline\bin\Debug\adxloader.dll.manifest'.
19:20:39:065 2416 3244 Getting the 'assemblyIdentity' element.
19:20:39:065 2416 3244 Success.
19:20:39:065 2416 3244 Getting the 'name' attribute.
19:20:39:066 2416 3244 Success. The name is 'PowerOutline, PublicKeyToken=521e0a50813e7ca0'.
19:20:39:066 2416 3244 Getting the 'name' attribute.
19:20:39:066 2416 3244 Success. The class name is 'PowerOutline.PoXllModule'.
19:20:39:066 2416 3244 Attempting to create a new instance of the XLL class.
19:20:39:093 2416 3244 Success.
19:20:39:093 2416 3244 Getting the dispid of the 'autoOpen' method.
19:20:39:110 2416 3244 Success.
19:20:39:110 2416 3244 Getting the dispid of the 'autoClose' method.
19:20:39:110 2416 3244 Success.
19:20:39:110 2416 3244 Getting the dispid of the 'autoAdd' method.
19:20:39:110 2416 3244 Success.
19:20:39:110 2416 3244 Getting the dispid of the 'autoRemove' method.
19:20:39:110 2416 3244 Success.
19:20:39:110 2416 3244 Getting the dispid of the 'autoFree' method.
19:20:39:111 2416 3244 Success.
19:20:39:111 2416 3244 Getting the dispid of the 'autoFree12' method.
19:20:39:111 2416 3244 Success.
19:20:39:111 2416 3244 Getting the dispid of the 'addInManagerInfo' method.
19:20:39:111 2416 3244 Success.
19:20:39:111 2416 3244 Getting the dispid of the 'addInManagerInfo12' method.
19:20:39:111 2416 3244 Success.
19:20:39:111 2416 3244 Getting the dispid of the 'Dispose' method.
19:20:39:111 2416 3244 Success.
19:20:39:111 2416 3244 Getting the dispid of the 'initialize4' method.
19:20:39:111 2416 3244 Unknown name.

19:20:39:116 2416 3244 Unknown name.

19:20:39:116 2416 3244 Start - xlAddInManagerInfo12.
19:20:39:116 2416 3244 Creating a new instance of the XLL loader.
19:20:39:116 2416 3244 Success.
19:20:39:116 2416 3244 Getting the CLSID of the managed XLL class.
19:20:39:117 2416 3244 Success.
19:20:39:117 2416 3244 Loading the configuration from the system registry.
19:20:39:117 2416 3244 Getting the latest CLR version.
19:20:39:117 2416 3244 The latest CLR version is 'v4.0.30319'.
19:20:39:117 2416 3244 The configuration has been loaded successfully.
19:20:39:117 2416 3244 Runtime version: v4.0.30319.
19:20:39:117 2416 3244 Assembly name: PowerOutline, Version=1.0.0.3, Culture=neutral, PublicKeyToken=521e0a50813e7ca0.
19:20:39:117 2416 3244 Class name: PowerOutline.PoXllModule.
19:20:39:117 2416 3244 Registry key: CLSID\{38064809-9880-3BC2-926C-2D8215EA3ABD}.
19:20:39:117 2416 3244 Attempting to create a new instance of the managed XLL class: CLR - v4.0.30319
19:20:39:117 2416 3244 Getting the base directory for the domain.
19:20:39:118 2416 3244 Success. The directory is 'C:\Users\Attiqe Ur Rehman\Source\Workspaces\PowerOutline\PowerOutline\bin\Debug\'.
19:20:39:118 2416 3244 Opening adxloader.dll.manifest.
19:20:39:118 2416 3244 Success. The manifest is 'C:\Users\Attiqe Ur Rehman\Source\Workspaces\PowerOutline\PowerOutline\bin\Debug\adxloader.dll.manifest'.
19:20:39:118 2416 3244 Getting the 'assemblyIdentity' element.
19:20:39:118 2416 3244 Success.
19:20:39:118 2416 3244 Getting the 'name' attribute.
19:20:39:118 2416 3244 Success. The name is 'PowerOutline, PublicKeyToken=521e0a50813e7ca0'.
19:20:39:118 2416 3244 Getting the 'name' attribute.
19:20:39:118 2416 3244 Success. The class name is 'PowerOutline.PoXllModule'.
19:20:39:118 2416 3244 Attempting to create a new instance of the XLL class.
19:20:39:118 2416 3244 Success.
19:20:39:118 2416 3244 Getting the dispid of the 'autoOpen' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'autoClose' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'autoAdd' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'autoRemove' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'autoFree' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'autoFree12' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'addInManagerInfo' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'addInManagerInfo12' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'Dispose' method.
19:20:39:119 2416 3244 Success.
19:20:39:119 2416 3244 Getting the dispid of the 'initialize4' method.
19:20:39:119 2416 3244 Unknown name.
19:20:39:120 2416 3244 Unknown name.



Thanks,
Attiqe
Posted 19 Jun, 2014 08:29:52 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Attiqe,

ExcelApp.COMAddins.Item(strMyComAddinProgId).Object returns a COM object, not the AddinModule class; this works in accordance with the Office object model. You call your method using late binding, see System.Type.InvokeMember().

Make sure that you register the project after adding the XLL module to your project. Also check if your project references AddinExpress.MSO.2005 of version 7.5.4072, not an older one; this often occurs if Copy Local is set to True on that reference.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2014 04:06:57 Top