Chris2015
Chris2015

Reputation: 1050

Add text to textbox macro

Why doesn't this code work to add text to textbox? I am sure the syntax is off somewhere, but not sure where.

    Label5.Text = "Add Text"

Thanks.

Upvotes: 0

Views: 12163

Answers (2)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

Impossible to say w/o a more extensive bit of code.

If the text box is actually an ActiveX Label (as suggested by its name), then like so:

Sub thing()
    Dim oSh As Shape
    Set oSh = ActiveWindow.Selection.ShapeRange(1)

    oSh.OLEFormat.Object.Caption = "Some text"

End Sub

If it's a normal text box or other shape that can contain text:

Sub thing()
    Dim oSh As Shape
    Set oSh = ActiveWindow.Selection.ShapeRange(1)

    oSh.TextFrame.TextRange.Text = "Some text"

End Sub

Upvotes: 1

Sorceri
Sorceri

Reputation: 8053

Its because its a shape. Get the shapes collection and locate the label then access the TextFrame2.TextRange.text

Upvotes: 0

Related Questions