Text Property

Applies To

AxisTitle Object, Button Object, Buttons Collection, Characters Object, ChartTitle Object, CheckBox Object, DataLabel Object, DialogFrame Object, DrawingObjects Collection, DropDown Object, DropDowns Collection, EditBox Object, EditBoxes Collection, GroupBox Object, GroupBoxes Collection, Label Object, Labels Collection, OptionButton Object, OptionButtons Collection, Range Object, TextBox Object, TextBoxes Collection.

Description

Returns or sets the text for the specified object, as shown in the following table. Read-write, except for the Range object, where this property is read-only. The Text property will not work with a drop-down, but it will work with a combination drop-down edit.

Object

Text

AxisTitle, ChartTitle

The title text.

Button

The button text.

Characters

The text of this range of characters.

Controls

The control text (check box, dialog frame, drop down, edit box, group box, label, and option button).

DataLabel

The data label text.

Range

The actual text appearing in a cell, as a string. For example, if a cell is formatted to show dollar signs, returning the text of a cell will show the dollar sign. This can be used to create readable text representations of the values on a worksheet. Read-only.

TextBox

The text in the text box.


Example

This example sets the text in text box one on Sheet1. Existing text, if any, is deleted before the new text is set.


Worksheets("Sheet1").TextBoxes(1).Text = "This is a test"

This example sets the text for the chart title of Chart1.


With Charts("Chart1")
    .HasTitle = True
    .ChartTitle.Text = "First Quarter Sales"
End With

This example sets the axis title text for the category axis in Chart1.


With Charts("Chart1").Axes(xlCategory)
    .HasTitle = True
    .AxisTitle.Text = "Month"
End With

This example replaces the text of the label named "Label 1" on the dialog sheet Dialog1 with the current date and time.


DialogSheets("Dialog1").Labels("Label 1").Text = Now()

This example erases the text on every button on Sheet1.


Worksheets("Sheet1").Buttons.Text = ""

This example illustrates the difference between the Text and Value properties of cells that contain formatted numbers.


Set c = Worksheets("Sheet1").Range("B14")
c.Value = 1198.3
c.NumberFormat = "$#,##0_);($#,##0)"
MsgBox c.Value
MsgBox c.Text

For help about using the Text worksheet function in Visual Basic, see "Using Worksheet Functions in Visual Basic" in online Help.