index > Visual Studio Tools for Office > Retrieve cell value

Retrieve cell value

Hello,

I would think this would be a rather easy task but it has thoroughly confused me.

I am trying to take the value in cell[1,10], which is the result of a formula, and assign it to a variable in my code. So far, I have been unable to do this. I am using Excel 2003, C#.

This is my code:

If (dbConnection.Open != null)

{

Cells[1,10] = "Success";

}

//Below is what does not work.

string aString = (string)cells[1,10];

I have also tried,

string aString = Cells.get_Value(Cells[1,10]);

Any help would be very much appreciated.

Thanks,

ds




dsMqplp
dsMqplp

Hi

Quite easy when you know how.

Excel.Range objRange = (Excel.Range)objYourSheet.Cells[1,10];
strData = objRange.get_Value(Missing.Value).ToString();

Regards




Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
Mike Walker
Great, thanks! Works good.


dsMqplp
dsMqplp

I have a similar issue, but I can't get the code above to work, what is Missing.value? Could you include a larger code snippet which includes object definitions? That would be very helpful to me.




Jonathan
coexplorer

"missing" is what you need to pass to [Optional] COM parameters if you don't want to specify a value. If you're working in VSTO, then missing (as an object) is predefined for you and you can use that. If you're working outside of VSTO, then you have to declare it

object missing = System.Type.Missing;

or you can use System.Type.Missing directly in your code (just more finger-work ).




-- Cindy Meister (Word MVP)
Cindy Meister
reply 5

You can use google to search for other answers

 

More Articles

• Document Protection disables too much!?
• Dumping the full ribbon XML in Outlook 2007...
• Bug fix request
• How to Programmatically Retrieve Document Digital Signature Detai...
• Serious Smart Tags Problem (a bug?)
• DllUnregisterServer issue; err code 0x80070005
• Runtime Library
• .h include files not Found!!
• How Digital Signature work.
• VB.Net COM Add-In for Excel Nightmare! please help.
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Infopath 2007 - Odd Problem with Decimal
• Security and permissions on a VSTO server
• Re: PLEASE READ FIRST: Non-VSTO Question
• Can't Create VSTO project
• Extracting HTML from a MailItem object.
• Error:"The Assembly could not be fo
• Sending email using Outlook 10.0 Object
• Outlook Add-in doesn't work after instal
• cell formatting
• VSTO and Windows application
• InfoPath XSL Bug
• Word.Docs in VB.Net
• Mangage code about save Screen to PPT
• coding in VS 2005 for infopath
• VSTO 2005 Outlook Add-In reply event not

Hot Articles

• Deployment and security aspects
• How to add button to toolbar similar as
• Help on exporting data from C# 2005 to a
• is there a "link pressed" even
• Multithreading in VBA for Excel
• What Kind of things can I do with VSTO?
• Does Microsoft Office InfoPath 2003 Tool
• VSTO Solution is not running on client's
• Deployment seems to be broken in VSTO...
• Make smart tag recognizer stop recognizi
• sheet change event target (range) and na
• Outlook Addin Installer (Default Path)
• Reading data from Excel through VB.NET
• Office Web Components Cut and Paste Event
• Shortcut to word template for VSTO appli

Recommend Articles

• set_Style throws error in Arabic OS
• Can not add Msosec.dll to the fully trus
• HtmlBody problem's
• taskpane
• Data Source
• Deleting a line break
• How to Programmatically Retrieve Documen
• VSTO 2005 Excel Template Deployment - Ex
• Bookmark Update Problem
• Something Missing with Intellisense due
• How to get char(13)&char(10) in Exce
• Visio diagram from vb.net
• Outlook 2003's NewMailEx event handling
• B2TR and VSTO v3?
• File or assembly name Microsoft.VisualSt