LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Range.Value2 in C# (Excel 2007, VSTO 2008)?

After doing intense research on the net, I finally found out that I cannot
simply use VSTO 2008 ThisAddIn to create UDFs (for Excel 2007), at least not
without writing any further VBA code to call the UDF defined. I thought this
was possible, but read that actually to write UDFs without VBA I either have
to use COM AddIns or Automation AddIns. I'd be happy to be proved I'm wrong.

So I wrote an Automation AddIn for Excel 2007 (using C#). It again took me a
long time to understand that unlike with VB.NET in C# I simply cannot use
myRange.Value but must use myRange.Value2 instead. Fact is, myRange.Value
simply doesn't exist as a public accessible field in
Microsoft.Office.Interop.Excel. (Of course all the code examples on the net
fail to mention this fact.) How do I then access and modify the value of a
cell?

The following code example works fine:

public String Foo(object Range)
{
Type type = Range.GetType();
return type.ToString();
}

However, the next example does not work:

public String Foo2(object Range)
{
Excel.Range rng = (Excel.Range) Range;
Object obj = (Object) rng.Value2; // (Object)rng.Cells[1,1].Value2 does
not work either
Type type = obj.GetType();
return type.ToString();
}

The result in Excel is #VALUE! independent of what type the method parameter
actually is. I have no clue whatsoever why I cannot access rng.Value2. Can
anyone explain? Thanks.

Fabz


 
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
Help with Range.Value2, Range.Text and UDFs JsjsLim Excel Programming 6 June 26th 09 05:30 AM
Deploying Excel 2007 VSTO Addin Ross Culver[_3_] Excel Programming 0 February 28th 09 07:26 PM
0x800a03ec - VB 2005 or VB 2008 & Excel 2007 (Range Text) (AddData Stephen Plotnick[_2_] Excel Programming 0 March 28th 08 02:09 AM
Excel 2007 Add-in with VSTO MadZebra Excel Programming 5 February 29th 08 12:52 AM
Excel & C# NullReference Error when trying to set Range.Value2 Chuck Excel Programming 1 August 2nd 06 11:01 PM


All times are GMT +1. The time now is 04:18 AM.

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

About Us

"It's about Microsoft Excel"