简体   繁体   中英

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. Then later I've found that i can do this (Resize shape to fit text in 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. 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

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 :-)

Bon courage!

Steve

@TimothyRylatt If you don't want to help, then just scroll by.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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