通过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
相关产品推荐
相关产品推荐

