Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Managed code error handling from VBA Prasanna Excel Programming 0 January 10th 08 04:02 PM
Udfs and eventhandler for excel in managed code [email protected] Excel Programming 0 February 15th 07 10:52 AM
Does MS Office 2002 have support for managed code extensions? Mircea Pleteriu Excel Programming 1 February 14th 05 08:17 AM
refedit control in 2003 and managed code add-in? Nick Hodge Excel Programming 2 September 7th 04 03:16 PM
.Net Managed Code - Excel Francois[_3_] Excel Programming 0 August 12th 04 07:37 AM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"