0
votes

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

enter image description here

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.

1
The short answer is, yes. But SO, as I am sure you know by now, isn’t a code writing service.Timothy Rylatt
@TimothyRylatt Ur right, so I've tried to start my code but I don't found the method to resize/fitSatanas
You evidently haven't looked very hard. Try using the Object Browser in the VBE to find the text related objects. e.g. see: TextFrame and AutoSizeTimothy Rylatt

1 Answers

0
votes

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.