App can't see Excel namespace

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

App can't see Excel namespace
 
Richard Freeman


Guest


I've created the "My First Addin" addin from the manual exactly as it shows and it works perfectly (VS2005, Excel 2000). Next I wanted to add a User Defined Function so I added the following code - actually Sergey's code :-)

VS can't see the Excel namespace so I get the squiggly line under "Excel.Range". I've tried various "Imports" but none seem to improve the situation (Microsoft.Office.Core for instance).

Am I missing something obvious?
Thanks,
Rich.
--------------------------------------

Public Function MyFunc(ByVal Range As Object) As String
Dim myRange As Excel.Range
Dim retVal As String

retVal = "Empty"
Try
myRange = Range
retVal = "Range Size [" + myRange.Rows.Count.ToString() + ":" + myRange.Columns.Count.ToString() + "]"
Catch ex As Exception
Return ex.Message
Finally
If Not (myRange Is Nothing) Then
Marshal.ReleaseComObject(myRange)
End If
End Try
Return retVal

End Function
Posted 08 Jan, 2006 13:36:27 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Richard.

You need to add a new reference to Microsoft Excel via the Add Reference dialog in VS.
Posted 09 Jan, 2006 06:08:58 Top
Rich


Guest


Thanks Sergey - I think I must have been tired on Sunday....

ok - so that problem solved, the code builds without problem. I register the ADX addin, run Excel - 'my first button' appears but entering =MyFunc(A1:B2) into a cell just yields "#Name" as if Excel is unaware of the new function.

Is there anything else needed to 'register' a UDF with Excel?

Thanks for your patience :-)
Rich.
Posted 10 Jan, 2006 13:18:31 Top
Rich


Guest


Actually thinking some more I wonder if I need a vba wrapper to reference the Add-In. I'll do some research.
Rich.
Posted 10 Jan, 2006 13:43:02 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Richard.

Unfortunately Excel 2000 cannot call a function directly in a COM Add-in from a worksheet cell formula. You need to use Excel 2002 or later.
Posted 10 Jan, 2006 22:04:50 Top
Guest


Guest


Thanks Sergey - yes I got this far last night. In Excel 2000 you definitely need a wrapper (http://support.microsoft.com/default.aspx?scid=kb;en-us;Q256624)

Unfortunately this example uses the VS add-in component (Application.COMAddIns.Item("MyAddin.Connect").Object) rather than the Add-In-Express components.

Is there anyway for the wrapper to "connect" to the Add-In-Express components in the same way that Microsoft describe in their article?

Thanks,
Rich
Posted 11 Jan, 2006 05:00:47 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Richard.

You can connect to the ADX based add-in in the same way as Microsoft described. You just need to use the progId of your addinmodule instead of the 'MyAddin.Connect'.
Posted 11 Jan, 2006 06:44:14 Top
Rich


Guest


Success!!!

Thanks Sergey - actually the ProgId is "Addin1Shim.Proxy" (found by enumerating the ProgId's of the ComAddins collection)

So UDF's can be written in .net for Excel2000 using ADX :D

Ok - now on to writing that killer add-in!

Thanks again,
Rich
Posted 11 Jan, 2006 09:41:48 Top