Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
0 out of 2 rated this helpful - Rate this topic

How to: Send Values to Worksheet Cells

Updated: July 2008

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

You can put a value in a cell by using a range. The following examples use the Value2 property of the range instead of the Value property to avoid having to pass in parameters.

To send a value to a cell in a document-level customization

  • Create a NamedRange control on cell A1 of Sheet1, and assign a string value to the Value2 property. Place the following code in the Sheet1 class.

    Microsoft.Office.Tools.Excel.NamedRange nr =
        this.Controls.AddNamedRange(this.Range["A1", missing], "NamedRange1");
    
    nr.Value2 = "Hello World";
    

To send a value to a cell in an application-level add-in

  • Create a Range that represents cell A1 of Sheet1, and assign a string value to the Value2 property.

    Excel.Range rng = this.Application.get_Range("A1", missing);
    rng.Value2 = "Hello World";
    

The following condition causes an exception:

User input can include information that is potentially malformed, malicious, or not valid. Always check that the values that a user enters conform to the requirements for your application before using the values. For more information, see User Input Validation in Windows Forms.

Date

History

Reason

July 2008

Added a code example that can be used in an application-level add-in.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.