VBA Printing the value in a textBox

Viewed 5219

I'm trying to print the value of a textbox in excel using VBA. The textbox is title "TextBox 6" and this is the code I used:

Debug.Print (wSheet.Shapes("TextBox 6").TextFrame.Characters.Text)

wSheet is the main worksheet where the textbox is located. The error I get is:

The item with the specified name wasn't found.

Any help would be great! Thanks in advance!

2 Answers

You can use the ActiveX Controls. Add a textbox to the sheet. enter image description here

Right click in textbox and select the view code menu

enter image description here

Then try the following code:

Private Sub TextBox1_Change()
    Cells(1).Value = TextBox1.Text
End Sub
Private Sub this()
    Debug.Print ; ActiveSheet.OLEObjects("TextBox1").Object.Value
End Sub
Related