Gerd Goldberg
Posts: 8
Joined: 2007-06-07
|
Hello everybody,
I have the following problem:
In the AddinModule, I defined a public static variable. When pressing a button on a AddinCommandBar, I change the value of the variable, for example to set a status or something like this.
In the ExcelAddinModule I have defined a User-defined-Function. The function should have access to the variable defined in the AddinModule, so that the calculation of the UDF can react to the status that is stored in the public static variable of the AddinModule.
I did read a lot about the CurrentInstance variable of the AddinModule, but it does not work, the value of the variable is always the same in the UDF!
Here is the code:
AddinModule:
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using Excel = Microsoft.Office.Interop.Excel;
namespace TT
{
/// <summary>
/// Add-in Express Add-in Module
/// </summary>
[GuidAttribute("D6903E35-AF0B-418B-9AA7-4D94D21401FC"), ProgId("TT.AddinModule")]
public class AddinModule : AddinExpress.MSO.ADXAddinModule
{
public static string hauptName = \"Hauptname\";
public AddinModule()
{
InitializeComponent();
}
private AddinExpress.MSO.ADXCommandBar adxCommandBar1;
private AddinExpress.MSO.ADXCommandBarButton adxCommandBarButton1;
#region Component Designer generated code
/// <summary>
/// Required by designer
/// </summary>
private System.ComponentModel.IContainer components;
/// <summary>
/// Required by designer support - do not modify
/// the following method
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.adxCommandBar1 = new AddinExpress.MSO.ADXCommandBar(this.components);
this.adxCommandBarButton1 = new AddinExpress.MSO.ADXCommandBarButton(this.components);
//
// adxCommandBar1
//
this.adxCommandBar1.CommandBarName = "adxCommandBar1";
this.adxCommandBar1.CommandBarTag = "9d8a332c-a084-446f-98e2-ef67db996d9b";
this.adxCommandBar1.Controls.Add(this.adxCommandBarButton1);
this.adxCommandBar1.UpdateCounter = 2;
//
// adxCommandBarButton1
//
this.adxCommandBarButton1.Caption = "BottonTT1";
this.adxCommandBarButton1.ControlTag = "d6bcec12-2e00-49dd-9a87-67a158d6c036";
this.adxCommandBarButton1.ImageTransparentColor = System.Drawing.Color.Transparent;
this.adxCommandBarButton1.UpdateCounter = 3;
this.adxCommandBarButton1.Click += new AddinExpress.MSO.ADXClick_EventHandler(this.adxCommandBarButton1_Click);
//
// AddinModule
//
this.AddinName = "TT";
this.SupportedApps = AddinExpress.MSO.ADXOfficeHostApp.ohaExcel;
}
#endregion
#region Add-in Express automatic code
// Required by Add-in Express - do not modify
// the methods within this region
public override System.ComponentModel.IContainer GetContainer()
{
if (components == null)
components = new System.ComponentModel.Container();
return components;
}
[ComRegisterFunctionAttribute]
public static void AddinRegister(Type t)
{
AddinExpress.MSO.ADXAddinModule.ADXRegister(t);
}
[ComUnregisterFunctionAttribute]
public static void AddinUnregister(Type t)
{
AddinExpress.MSO.ADXAddinModule.ADXUnregister(t);
}
public override void UninstallControls()
{
base.UninstallControls();
}
#endregion
public Excel._Application ExcelApp
{
get
{
return (HostApplication as Excel._Application);
}
}
private void adxCommandBarButton1_Click(object sender) {
hauptName = \"new\";
}
}
}
ExcelAddinModule:
using System;
using System.Runtime.InteropServices;
namespace TT
{
/// <summary>
/// Add-in Express Excel Add-in Module
/// </summary>
[GuidAttribute("D82E6BCA-F960-42B7-B6A7-833D5324BF8B"),
ProgId("TT.ExcelAddinModule1"), ClassInterface(ClassInterfaceType.AutoDual)]
public class ExcelAddinModule1 : AddinExpress.MSO.ADXExcelAddinModule
{
public ExcelAddinModule1()
{
}
#region Add-in Express automatic code
[ComRegisterFunctionAttribute]
public static void AddinRegister(Type t)
{
AddinExpress.MSO.ADXExcelAddinModule.ADXExcelAddinRegister(t);
}
[ComUnregisterFunctionAttribute]
public static void AddinUnregister(Type t)
{
AddinExpress.MSO.ADXExcelAddinModule.ADXExcelAddinUnregister(t);
}
#endregion
public string ttFunktion() {
return AddinModule.hauptName;
}
}
} |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Gerd.
It happens because the COM add-in and UDF are in different app domains.
Please try the following workaround:
http://www.add-in-express.com/projects/comaddinandudf.zip
P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found. |
|
nitin c
Posts: 79
Joined: 2007-05-18
|
I am not sure I understood the code from the zip, but I too had a problem with different app domains and I ended up implementing IPC remoting to get the 2 talking.
- Nitin |
|
Gerd Goldberg
Posts: 8
Joined: 2007-06-07
|
Hello Sergey,
thank you for your fast response!
I tried the project in the ZIP-archive but unfortunately, it does not work!
I can build the project and I can register it successfully. But when I start EXCEL, I get the error message:
ADX Loader Error
Interface not supported
I use the following software:
Add-In-Express 2.8.1763
EXCEL 2003 SP2
Visual C# Express 2005
thank you in advance!
Gerd |
|
Gerd Goldberg
Posts: 8
Joined: 2007-06-07
|
Hello Sergey,
it seems to work now!
I simply copied the vital part of your code in one of my projects:
private void AddinModule_AddinStartupComplete(object sender, EventArgs e) {
object val = ExcelApp.Evaluate("myFunc()");
}
Now ist works fine!! :) :)
To use the ExcelApp.Evaluate: is it a workaround or a wanted feature? |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Gerd.
This is just a workaround. Please let me know if you face any difficulties with the code. |
|