Access the Text Box by Name

Access the Text Box by Name

Earlier, text boxes were accessed by index from the Worksheet.TextBoxes collection, but now you can also access a text box by name from this collection. This is a convenient and quick way to access your text box if you already know its name.

The following sample code first creates a text box and assigns it some text and a name. Then, in the next lines, we access the same text box by its name and print its text.

C# code to access the text box by name

Console output generated by the sample code

Here is the console output of the above sample code.

This is MyTextBox