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.

How to: Display a String in a Worksheet Cell

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.

This example demonstrates how to display text in a cell programmatically. To display text in cell, use either a NamedRange control or a native Excel range object.

This example uses a NamedRange control named message. The control must be added to a document-level customization at design time. The following code must be placed in a sheet class, not in the ThisWorkbook class.

To display text in a NamedRange control

  • Set the value of the NamedRange control to Hello World.

    this.message.Value2 = "Hello world";
    

The following code creates a new range programmatically and then assigns a value to it.

To display text in an Excel range

  • Retrieve the range at cell A1 on Sheet1 and set the value to Hello World.

    Excel.Range rng = this.Application.get_Range("A1", missing);
    rng.Value2 = "Hello world";
    
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft