How to put the text box object on a specific cell when automating Excel?

We use VB.Net to automate Excel and try to place multiple lines of text on Excel worksheets that we can set to not print. Between these we will have printable reports.
If we add a text box object and set the print object to false, we can do so. (If you have other ways, please guide me)

The code for adding a text box is :

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 145.5, 227.25, 304.5, 21#)

But positioning is divided. We need a way to Put it on a specific cell and then adjust it with the cell. When we know which cell to put on it, how can we find where it is placed?

If you have a cell name or location, you can do the following:

With ActiveSheet
.Shapes.AddTextbox msoTextOrientationHorizontal, .Cells(3,2).Left, .Cells(3,2).Top, .Cells(3,2 ).Width, .Cells(3,2).Height
End With

This will add a text box on cell B3. When B3 is resized, the text box is also.

We use VB.Net to automate Excel and try to put multiple lines of text on an Excel worksheet that we can set to not print. Between these we will have a printable report.
If we add a text box object and set the print object to false, we can do so. (If you have other ways, please guide me)

The code for adding a text box is :

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 145.5, 227.25, 304.5, 21#)

But positioning is divided. We need a way to Put it on a specific cell, and then adjust it with the cell. When we know which cell to put on it, how can we find where it is placed?

If you have the cell name or location, you can do the following:

 With ActiveSheet
.Shapes.AddTextbox msoTextOrientationHorizontal, .Cells(3,2).Left, .Cells(3,2).Top, .Cells(3,2).Width, .Cells(3,2). Height
End With

This will add a text box on cell B3. When B3 is resized, the text box is also.

Leave a Comment

Your email address will not be published.