How to enable Grow Text Box To Fit in MS Publisher using VBA

人走茶凉 提交于 2019-12-11 13:24:24

问题


Hi MS Publisher VBA programmers :-)

What seems so simple is actually not documented. All I need to do is be able to insert text programmatically into a text box then have the text resize vertically expanding itself as I add more text.

This works fine if I do it manually by inserting TextBox and choosing the "Grow Text Box To Fit" option in the Text Fit drop-down in the Format tab of the TextBox.

This code doesn't work:

Sub myGrowToFit()
        Set myTextBox = ActiveDocument.Pages(1).Shapes.AddTextbox _
             (Orientation:=pbTextOrientationHorizontal, _
             Left:=0, Top:=0, _
             Width:=100, Height:=40)
        myTextBox.TextFrame.TextRange.text = "Line1" & vbLf & "Line2" & vbLf & "Line3" & vbLf & "Line4"
        myTextBox.TextFrame.AutoFitText = pbTextAutoFitGrowToFit
        MsgBox ("Press OK to Continue After You View The Result")
        myTextBox.Delete
End Sub

Any ideas? Thanks.

来源:https://stackoverflow.com/questions/47191403/how-to-enable-grow-text-box-to-fit-in-ms-publisher-using-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!