Changing ALL textboxes' 1) widths & 2) horizontal absolute positions

K

K J

Hi! I have a 200-page document with about 600 textboxes in it, each
containing different text.

Every single text box needs:
1) a width of exactly 2.2" and
2) an absolute horizontal position of 4.3" to the right of Column.

Note:
- Text box heights can be anything (each box's height is already
appropriate for its content, and each is already almost correct,
though not quite, as far as width, so I don't think changing the width
to a uniform 2.2" will give me text problems. All I need my macro to
do is leave the height of the text box it's on alone.)
- Text box VERTICAL positions can be anything (each box is already
placed appropriately to its paragraph. Some are locked, some aren't.
All I need my macro to do is leave the vertical positioning of the
text box it's working on alone.)

Ideally, I would make a macro that could be run once and would change
every text box in the document.

But, if that's not possible, I would also appreciate a macro that I
could assign to a hotkey so all I would have to do is click a text box
with my right hand, run the resizing macro with my left hand, and
repeat by clicking and running on another text box.



I tried recording a macro while resizing and repositioning a box by
hand, looking at the code, taking out anything that didn't seem to be
related to text box width or text box horizontal positioning, and
running my new macro on a text box (click on the box, then click "run"
on the macro), but that didn't work at all! In the absence of ANY
commands about vertical positioning, instead of leaving my poor text
box where it was, vertically, it moved it near the bottom of the
page! (I think once it moved it to the top.)



Obviously I'm going about this wrong, and after searching as hard as I
could to "RTFM" myself, I am completely stuck and have realized that I
need to simply ask someone the terrible newbie question, "I need to do
_X_. What's the code?"

Thanks!
KitKat
 
H

Helmut Weber

Hi ,
Every single text box needs:
1) a width of exactly 2.2" and
2) an absolute horizontal position of 4.3" to the right of Column.

ad 2: I don't know what column means in that context

You may try to adapt this to your needs:

Sub Macro4()
Dim oSHp As Shape
For Each oSHp In ActiveDocument.Shapes
If oSHp.Type = msoTextBox Then
oSHp.Width = InchesToPoints(2.2)
oSHp.Left = InchesToPoints(4.2) ' your value
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

K J

Okay, that worked like a charm, Helmut!

One more question, though:

I realized that there ARE a few extra text boxes that aren't the ones
I want to alter. They're scattered throughout the document, but one
thing all the ones I want to alter have in common and that other text
boxes don't share with them is that they're set (in the text box's
properties) with a fill at RGB 234,234,234.

What's the most efficient way of sticking in some sort of condition
into your code that checks for this before altering the width &
placement of the text box?

Thanks,
KitKat
 
H

Helmut Weber

Hi Kitkat,

If oSHp.Fill.BackColor <> RGB(234, 234, 234) Then

or forecolor

see help for fillformat object.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

K J

Well, if you weren't in Bavaria, Germany, I'd have to hug you.

It works.

For future archival reference, here's the final code:



Sub ResizeAndRepositionAllTextBoxes()
'
' ResizeAndRepositionAllTextBoxes Macro
' Macro created 2/22/2007 by kitkat
'
Dim oSHp As Shape
For Each oSHp In ActiveDocument.Shapes
If oSHp.Type = msoTextBox And oSHp.Fill.ForeColor = RGB(234, 234,
234) Then
oSHp.Width = InchesToPoints(2.2)
oSHp.Left = InchesToPoints(4.3) ' your value
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top