How do you place a text box object over a specific cell in Excel Automation?

We automate Excel using VB.Net and try to place several lines of text on an Excel worksheet that we can set so as not to print. Between them we would have printed reports. We can do this if we add text field objects and set the print object parameter to false. (If you have another way, direct me)

Code for adding a text field:

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

but positioning in points. We need a way to place it in a specific cell and put it in a cell. How can we find out where to express it when we just know which cell has flipped?

+4
source share
2 answers

If you have a cell name or position, you can do:

 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 above cell B3. When B3 changes, the text box also.

+8
source

When copying and pasting a text field, Excel will place a new text field on top of the selected cell. Thus, you can achieve this very easily by simply using the VBA copy and paste commands. This can be especially useful if you intend to use many similar text fields, since you are effectively creating a text field template.

0
source

Source: https://habr.com/ru/post/1276715/


All Articles