ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Retrieving Current Excel Instance from Automation Add-IN (https://www.excelbanter.com/excel-programming/325187-retrieving-current-excel-instance-automation-add.html)

mduncan

Retrieving Current Excel Instance from Automation Add-IN
 
I have created an Automation Addin with the following code.

[ClassInterface(ClassInterfaceType.AutoDual)]
public class TestFunctions
{
private ApplicationClass excelApplication;

public TestFunctions()
{
// this.excelApplication = SOMETHING
}

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(ty pe));
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(ty pe),false);
}

private static string GetSubKeyName(Type type)
{
string s = @"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";
return s;
}

Using the code above I want to grab the instance of Excel THAT THE ADD_IN is
RUNNING in. I tried this.excelAppication = new ApplicationClass(), but that
just creates a new excel instance.

Any suggestions would be very helpful.

Thank you,

mduncan

Simon Murphy[_4_]

Retrieving Current Excel Instance from Automation Add-IN
 
If its a vs office addin project:
the boiler plate code should include an
object called applicationObject, you should be able to reference that (its
private within the connect class so you'll have to make it public/global or
put an accessor routine in)
applicationObject is set on connection

if its a vs office project:
The boiler plate code should include an
Excel.Application called ThisApplication, you should be able to reference
that directly?
(I'm using VS.net 2003)

cheers
simon

"mduncan" wrote:

I have created an Automation Addin with the following code.

[ClassInterface(ClassInterfaceType.AutoDual)]
public class TestFunctions
{
private ApplicationClass excelApplication;

public TestFunctions()
{
// this.excelApplication = SOMETHING
}

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(ty pe));
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(ty pe),false);
}

private static string GetSubKeyName(Type type)
{
string s = @"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";
return s;
}

Using the code above I want to grab the instance of Excel THAT THE ADD_IN is
RUNNING in. I tried this.excelAppication = new ApplicationClass(), but that
just creates a new excel instance.

Any suggestions would be very helpful.

Thank you,

mduncan


mduncan

Retrieving Current Excel Instance from Automation Add-IN
 
Thank you. The on connection solution works perfectly!

"Simon Murphy" wrote:

If its a vs office addin project:
the boiler plate code should include an
object called applicationObject, you should be able to reference that (its
private within the connect class so you'll have to make it public/global or
put an accessor routine in)
applicationObject is set on connection

if its a vs office project:
The boiler plate code should include an
Excel.Application called ThisApplication, you should be able to reference
that directly?
(I'm using VS.net 2003)

cheers
simon

"mduncan" wrote:

I have created an Automation Addin with the following code.

[ClassInterface(ClassInterfaceType.AutoDual)]
public class TestFunctions
{
private ApplicationClass excelApplication;

public TestFunctions()
{
// this.excelApplication = SOMETHING
}

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(ty pe));
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(ty pe),false);
}

private static string GetSubKeyName(Type type)
{
string s = @"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";
return s;
}

Using the code above I want to grab the instance of Excel THAT THE ADD_IN is
RUNNING in. I tried this.excelAppication = new ApplicationClass(), but that
just creates a new excel instance.

Any suggestions would be very helpful.

Thank you,

mduncan



All times are GMT +1. The time now is 08:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com