You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过VBA实现文本自动适配形状大小的技术咨询

运行以下VBA代码
Sub Macro1()

'Delete all shapes
For i = ActiveSheet.Shapes.Count To 1 Step -1
    ActiveSheet.Shapes(i).Delete
Next i

'Add rectangle
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, Left:=50, Width:=100, Top:=50, Height:=40)
    .TextFrame2.MarginLeft = 0
    .TextFrame2.MarginRight = 0
    .TextFrame2.MarginTop = 0
    .TextFrame2.MarginBottom = 0
    .TextFrame2.VerticalAnchor = msoAnchorMiddle
    .TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignCenter
    .TextFrame2.TextRange.Font.Size = 30
    .TextFrame2.AutoSize = msoAutoSizeTextToFitShape
    .TextFrame2.TextRange.Characters.Text = "Stackoverflow"
End With

End Sub

下图展示了问题现象:
问题展示

感谢您的帮助

内容的提问来源于stack exchange,提问作者Kram Kramer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 13:52:04