Howto set range in Excel

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

Howto set range in Excel
From VBA to .Net 
Tom Nordal


Guest


Hi,

In VBA I use this code


Dim r As Range

Set r = Range("A10")


How can I translate this to .Net, I have searched the forum with no luck.

regards,
Tom
Posted 02 Jun, 2011 01:19:57 Top
Eugene Astafiev


Guest


Hi Tom,

The following code works like a charm on my PC:
Excel.Worksheet workSheet = ExcelApp.ActiveSheet as Excel.Worksheet;
Excel.Range rng = workSheet.Range["A10"];
rng.Value = "test";


BTW What version and build number of Add-in Express do you use?
Posted 02 Jun, 2011 03:48:12 Top
Tom Nordal


Guest


Hi,

Not working,

I convert you example to VB

Dim wsActive As Excel.Worksheet = ExcelApp.ActiveSheet
Dim rng As Excel.Range = wsActive.Range("A10")
   rng.Value = "Test"



When I run, the code stops on rng.value = "test" with this msg:

System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2146827284
Message="Exception from HRESULT: 0x800A03EC"

I use VS2008 and Add-in Express 2010 6.4.3056.2005

regards,
Tom
Posted 02 Jun, 2011 07:01:57 Top
Eugene Astafiev


Guest


Hi Tom,

Unfortunately I wasn't able to reproduce the issue on my side. Do you test the code against a newly created clean worksheet?

Anyway, to get assistance with host applications?Â?Ð?é objects, their properties, and methods as well as help info, use the Object Browser. Go to the VBA environment (in the host application, choose menu Tools | Macro | Visual Basic Editor or just press {Alt+F11}), press {F2}, select the host application in the topmost combo and/or specify a search string in the search combo. Select a class /property /method and press {F1} to get the help topic that relates to the object.
Posted 02 Jun, 2011 07:30:18 Top
Tom Nordal


Guest


Hi,

I was able to find a solution. The problem are that my computers regional settings not are "en-US", but "NO" (Norwegian), and I don't have the "Microsoft Office 2003 Multilingual User Interface Pack" installed.

I find the solution:
http://msdn.microsoft.com/en-us/library/aa168494%28office.11%29.aspx


Thanks for your help,
Tom
Posted 02 Jun, 2011 07:59:25 Top
Eugene Astafiev


Guest


Hi Tom,

Good news! You broke the ice!

However, also you may be interested in the http://www.add-in-express.com/creating-addins-blog/2009/02/13/old-format-invalid-type-library/ article on our technical blog.
Posted 02 Jun, 2011 08:03:31 Top