views:

43

answers:

1

It's obviously possible from a demo i saw earlier but didn't catch enough details

I envision making a function call such as

=MyRTDReverse("keyvalue", "fieldName", [AC51])

or

=MyRTDReverse("keyvalue", [AB51], [AC51])  // where AB51 has the field name and AC51 has the field value

etc.

where updating the value in cell AC51 triggers a change

any samples/patterns on how this would work ?

Update - using .Net 3.5 + VSTO UPDATE 2 - would prefer to not use VSTO and instead make a UDF/RTD like call routine

A: 

To trigger something based on a value change in a cell, handle the Worksheet_Change event:

Private Sub Worksheet_Change(ByVal Target As Range) 
    'here, check whether Target, a Range, is one of your "trigger" cells,
    'and if it is, react accordingly
End Sub 

To define a custom function:

Function MyFunction(Argument1, Argument2)
    'do stuff with your arguments, and set MyFunction equal to the return value
End Function

In a cell, you can then use the function like = MyFunction("value", 3)

Jay
I'm not familiar with VB controlling Excel : C# VSTO you have to do some real "hacking" to create UDF's (User Defined Functions) in C#, and use them on the WorkSheet. I have a question up on the VSTO 2010 beta forum right now about this : http://social.msdn.microsoft.com/Forums/en-US/officedevelopmentprerelease/thread/85edd66b-b778-4836-b706-fae8c4af442c I'd hoped this would be simpler in Visual Studio 2010 beta 2, Office 2010 beta, etc. No response yet. I'd like to know in what context your example of defining a Function and calling it on a WorkSheet is created in : is this using VSTO ?
BillW
@BillW No, sorry, my response preceded the update, so I didn't piece the VSTO thing together -- my response is strictly within Excel, using VBA.
Jay
If you want to create Excel UDF's in .Net, you should have a look at [ExcelDna](http://exceldna.codeplex.com).
Govert