使用如下的代码,可以给Excel中插入的自选图形动态添加文字。以下代码是示例代码,请根据需要加以修改并利用。
代码如下:
Dim sh As Shape
Set sh = Sheet1.Shapes.AddShape(msoShapeHexagon, 120, 120, 40, 10 * Sqr(3))
sh.TextFrame.Characters.Text = "这里就填写自选图形的文字"
With sh.TextFrame.Characters.Font
.Name = "宋体"
.FontStyle = "倾斜"
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3
End With
With sh.TextFrame
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.AutoSize = False
End With