Setting cell width via VBA (Word 2003)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15640
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Setting cell width via VBA (Word 2003)

Post by ChrisGreaves »

The attached document holds a simple VBA macro.
I've been struggling with this for a couple of weeks now, and am desperate for guidance.

I have about 20 brochures, each like the attached sample.
I ought to standardize each brochure so that the table cells are congruent - each of the 13(?) cells in the table for a brochure being identical in height and width; Then of course I'll be editing my text to fit.

I thought this should be as easy as setting up 13 height/width assignment statements and turning them loose on each document.

Not so.

The Word 2003/VBA help files for .SetWidth say in part "The WdRulerStyle behavior described above applies to left-aligned tables. The WdRulerStyle behavior for center- and right-aligned tables can be unexpected; in these cases, the SetWidth method should be used with care.", so OK, there's probably a deisgn or bug thing going on.

If .Width won't do it and .SetWidth won't do it, what chance does a poor guy have?

The macro code displays the two selected cells widths as 227 and 203.1 respectively.
I figured that for them to be the same width, I'd have to st the width to the average of the two widths, but running the macro sends the table haywire.

If I can get these two cells adjusted automatically, I figure there is a chance of getting all 13 cells adjusted automatically, and then my 20 brochures will look nicely standardized.

Thanks for any hints, tips or, worst-case, a flat "This can't be done in VBA", to save me throwing away any more time.
1.png
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Setting cell width via VBA (Word 2003)

Post by HansV »

You'll have to turn off "Automatically resize to fit contents" in the options for the table:

ActiveDocument.Tables(1).AllowAutoFit = False

You should then better be able to set the Width property of cells.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15640
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Setting cell width via VBA (Word 2003)

Post by ChrisGreaves »

HansV wrote:You'll have to turn off "Automatically resize to fit contents"
:clapping: :fanfare: :hairout: :smile: :thankyou: :angel:
YOU'RE HIRED!

Thanks Hans.

I want my life back ...
He who plants a seed, plants life.