简体   繁体   English

自动使文本框(形状)适合 Word 文档中的文本

[英]Auto fit a textbox(shape) to a text in a Word document

To give the context of my problem, I have to work with documents with text boxes, these text boxes hide the whole sentence almost all the time, so I have to resize the text box by hand so that the text is visible.为了给出我的问题的上下文,我必须使用带有文本框的文档,这些文本框几乎一直隐藏整个句子,所以我必须手动调整文本框的大小,以便文本可见。 The problem is that on some documents there are over 700 text boxes.问题是在某些文档上有超过 700 个文本框。 Then later I've found that i can do this (Resize shape to fit text in EN) :后来我发现我可以这样做(调整形状以适应 EN 中的文本):

在此处输入图片说明

So I was wondering if there is a way to select all the text boxes and resize them automatically selecting this option with VBA.所以我想知道是否有办法选择所有文本框并自动调整它们的大小,并使用 VBA 选择此选项。 Thank you !谢谢 !

EDIT编辑

So I've tried to start my code doing this :所以我试图开始我的代码这样做:

Dim eShape As Word.shape
Dim i As Long
For i = ActiveDocument.Shapes.Count To 1 Step -1
Set eShape = ActiveDocument.Shapes(i)

Then I start the condition by checking the object type in this case TextBox with然后我通过检查在这种情况下 TextBox 的对象类型来启动条件

If eShape.Type = msoTextBox Then

But for the rest I didn't found the method to resize the element.但其余的我没有找到调整元素大小的方法。

Salut Satanas,致敬萨塔纳斯,

Assembled this from various bits of code found lying around several sites:从几个站点周围发现的各种代码中组合而成:

Sub AllTextBoxesAutoSize()
Dim MyShape As Shape
For Each MyShape In ActiveDocument.Shapes
    If MyShape.Type = msoTextBox Then
        MyShape.TextFrame.AutoSize = True
    End If
Next
MsgBox ("All text boxes autosized!")
End Sub

I added the MsgBox because otherwise it's not apparent that anything's happened :-)我添加了 MsgBox 因为否则它不会发生任何事情:-)

Bon courage!勇气可嘉!

Steve史蒂夫

@TimothyRylatt If you don't want to help, then just scroll by. @TimothyRylatt 如果您不想提供帮助,请滚动浏览。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM