samedi 28 mars 2015

How to insert text to a (worksheet) textbox using VBA in Excel?

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?


Aucun commentaire:

Enregistrer un commentaire