Name
shapes
.AddTextbox(Orientation
, Left
, Top
, Width
, Height
)
Synopsis
Draws a text box surrounded by a rectangular border and returns the text box’s Shape
object.
Argument |
Settings |
---|---|
|
An |
|
The horizontal position of the shape in points. |
|
The vertical position of the shape in points. |
|
The width of the shape in points. |
|
The height of the shape in points. |
Use the TextFrame
property to get or set the text in the shape and to set the formatting of the text. Unlike labels, text boxes do not automatically resize to fit their text. You must set the AutoSize
property as shown here:
Sub DrawTextbox( ) Dim ws As Worksheet, s As Shape Set ws = ActiveSheet ' Create label (height/width will be set by AutoSize). Set s = ws.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 1, 1) s.TextFrame.Characters.text = "This is some label text" ' Resize text box to fit text. s.TextFrame.AutoSize = True End Sub
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.