UDF + managed code

M

Michal

Hi,

I have followed this walktrough
http://msdn.microsoft.com/en-us/library/bb608614.aspx on MSDN that describes
how to call managed code from VBA.

All seems to be working fine ( when i execute CallVSTOMethod from vithin VBA
editor i will get "This is my data" in the first cell on the worksheet).

The problem comes when i try to call the function as a UDF. I will go to the
cell and write
=CallVSTOMethod()

Expecting to get the "This is my data" in the first cell. Insted of that i
will get an error "<Exception from HRESULT: 0x800A03EC>" on the
automation.ImportData line in the CallVSTOMethod VBA method.

When i debug the ImportData c# function i discovered that the exception
occurs at the
range1.Value2 = "This is my data"; line, particulary when trying to access
Value2 of range1 object.

The exception thrown there is :
range1.Value2 Cannot obtain fields or call methods on the instance
of type 'Microsoft.Office.Interop.Excel.Range' because it is a proxy to a
remote object.

Onece again if i execute the same code from VBA (by hitting F5 while cursur
is in the function) it works fine with no error.

Any ideas?

Thanx

PS: Im running VS 2008 and Excel 2007
 
N

ND Pard

A Function returns a value to the cell where it is entered.

If you create the following fuction:

Function CallVSTOMethod()
CallVSTOMethod = "This is my data"
End Function

then, when you enter =CallVSTOMethod
in cell A1 and press enter,
the value of cell A1 becomes:
"This is my data"

Good Luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top