View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
GSerjo GSerjo is offline
external usenet poster
 
Posts: 2
Default Incorrect UDF call

Hi All,

Ive created com automation add-in for Excel 2007 in Visual Studio 2008(I
use com automation add-in because Ive to create UDFs)

All works fine, but udf function is called before user is pressed Ok in
€śFunction Arguments€ť window, i.e. the function is called when all function
arguments are entered. How I can change this, i.e. the function should be
called ONCE and ONLY after €śOk€ť button is pressed.

Here is the code


[ComVisible(true)]
public interface IUDFs

{

void Test(object value1, object value2);

}



[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[Guid("6D3442CB-5DCB-44d1-8AFD-2693A8ACF465")]
[ProgId("AutomationAddin.UDFs")]
public class UDFs : IUDFs
{
public UDFs()
{

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

}

#region Implementation of IUDFs

public void Test(object value1, object value2)
{
if (value1 is Missing || value2 is Missing)
return;
//Do Work
}

#endregion

#region Register UnRegister Add-in

[ComRegisterFunction]
public static void RegisterFunction(Type type)
{

Registry.ClassesRoot.CreateSubKey(GetSubKeyName(ty pe,
"Programmable"));

RegistryKey key =
Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type , "InprocServer32"), true);

key.SetValue(string.Empty, Environment.SystemDirectory +
@"\mscoree.dll", RegistryValueKind.String);

}



[ComUnregisterFunction]
public static void UnregisterFunction(Type type)

{

Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(ty pe,
"Programmable"), false);

}



private static string GetSubKeyName(Type type, string subKeyName)
{

var subKey = new StringBuilder();
subKey.Append(@"CLSID\{");
subKey.Append(type.GUID.ToString().ToUpper());
subKey.Append(@"}\");
subKey.Append(subKeyName);
return subKey.ToString();

}
#endregion Register UnRegister Add-in

}

Thanks in advance for any help!

Thanks,
GSerjo