Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
UDF + managed code
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
UDF + managed code
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. "Michal" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Managed code error handling from VBA | Excel Programming | |||
Udfs and eventhandler for excel in managed code | Excel Programming | |||
Does MS Office 2002 have support for managed code extensions? | Excel Programming | |||
refedit control in 2003 and managed code add-in? | Excel Programming | |||
.Net Managed Code - Excel | Excel Programming |