3

I have inserted a text box in my worksheet, using the menu "Insert/Text Box" at the ribbon of Excel 2007. It has automatically been named as "TextBox 17". I am trying to set its value using my VBA code, but I can't figure out the way to do it. I even tried to run a single-line routine just to feed the textbox with some text (like the following and other combinations) but failed.

Sub test()
    Sheets(1).Shapes.item(14).Text = "eventually some text"
    Sheets(1).Shapes(14).Text = "eventually some text"
    Worksheets(1).Shapes(14).Value = "eventually some text"
    Sheets(1).Shapes("TextBox 17").Text = "eventually some text"
    Sheets(1).Shapes("TextBox 17").ControlFormat.Value = "eventually some text"
    Worksheets(1).Shapes(14).TextFrame.TextRange.Text = "eventually some text"
End Sub

While in research about this, I found answers only about activeX textboxes. But as far as I understood, the textbox I have inserted is not of this kind.

Can anybody help?

3 Answers 3

3

This seems to be working with no problem:

Sheets(1).Shapes(14).TextFrame.Characters.Text = "xxx"
Sign up to request clarification or add additional context in comments.

1 Comment

object doesn't support this method or property error, any idea?
2

I was able to set the text box contents with

Sub test()
    Sheets(1).Shapes.Item(14).TextFrame.Characters.Text = "eventually some text"
End Sub

Comments

0

You can put the text in a cell (maybe the one obscured by the text box) and set the text box value to the content of the cell (=$B$7). The cell's text color can be changed to white to hide it, too.

The drawback is that it's vulnerable to a user changing it manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.