Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrict table autosize to contents

Status
Not open for further replies.

ajh1

Programmer
Apr 22, 2010
31
US
I am running Word 2007 and working on documents with lots of tables in them. I am looking for a way to turn off the autosize to fit contents flag on a more global basis than having to tweak each table as I get to it. I find that Word likes to resize cells, which becomes particularly problematic when I have merged cells in the top rows of the table to create heading blocks over multiple columns. My goal on this particular task has been to have all the columns be basic multiples of 0.60". I find that Word likes to resize them to sizes like 0.59", 4.17", etc. which has been driving me nuts. I can understand making a particular column (or cell) wider to accommodate a long number string, but when they resize smaller without needing to it creates a lot of extra work. I suspect there is a nice indicator flag somewhere that I can set as a default, but haven't been able to identify the correct one.
I appreciate any suggestions you might make.

Al..
 
Right-click the table selectors (the little cross at the top left of the table when you hover over one), select AutoFit | Fixed Column Width.

If your tables are all identical, once you have created a table as you need it, save it as an AutoText entry for fast insertion.

If you need to change all existing tables, then you'll need a VBA guru (not me) to help you.


Regards: Terry
 
Thanks for the input. What I really want is to be able to set this at a high level for Word itself, not per table, or even per document. I realize existing tables may have to be reset.
Your tip will at least make it faster on a per table basis. I'm still getting used to Word 2007 so haven't mastered all of the right click functionality. I was on 2000 for too many years and got used to the various options and menu structures there.
I hadn't really thought about VBA as an option. I do a fair amount of VBA for Excel but haven't used it in the Word environment before. I suppose a single command on a document activation (perhaps associated with the Normal template) could suppress the autofit. The only downside then would be when for some instance I wanted autofit, would I have a tendency to need to repeatedly reactivate it when reopening a document. Food for thought.
Al..
 
Well the 'FixedColumnWidth' command can be added to the QAT, so I presume it must be available in VBA too. I cannot think of a method to change the default to fixed columns globally. That setting is not even part of Table Styles.

You need a Word VBA programmer to tell you if this is at all possible.



Regards: Terry
 
AFAIK, Microsoft made a decision as to what is the default for creating tables (FitToContent), and this is built into Word, and thus is not changeable (as a default).

Yes, you can change the value (to whatever you want) but this is an explicit action, after the fact.

That being said, going the Autotext route as tf1 suggests is likely your best best.

Perhaps I am wrong (and as you are talking about 2007 I very well may be), but:

" What I really want is to be able to set this at a high level for Word itself, not per table, or even per document."

is not possible.

Gerry
 
Thanks for the input. I was afraid of that. I so love programs that have decided they are smarter than the user regardless. At some point in time I may play with the VBA side and see what I can dream up, but I don't have the time during this current project so I'll just keep plugging away and mumbling under my breath.

al..
 
Well tables - powerful and useful as they are - have not had much attention by the Word developers since they introduced Table Styles. These are a great idea in theory but so far have yet to be practical for power users that need to control all aspects of a table.

A Table Style should include all the parameters of a table, not just pretty borders and shadings.

So AutoText is about the only solution available for now.


Regards: Terry
 
Well tables - powerful and useful as they are - have not had much attention by the Word developers since they introduced Table Styles. "

And Table Styles do not work all that well; they are rather...ummmm...eccentric in behaviour.

"a great idea in theory but so far have yet to be practical"

Indeed!

But even if they were, the issue still remains. The default structure of table objects is hard-coded into Word, and again, AFAIK it can not be changed which, to an extent, is reasonable. Something has to be a default. It would make for a very different situation if all object structures could have their defaults changed.

AutoText is your best solution. AutoText work quite well.

However.....if you know what you want for each table (and extrapolating, a specific column for each table...), then:
Code:
Sub ChangeAllTables()
Dim oTable As Table
For Each oTable In ActiveDocument.Tables()
   With oTable.Columns(2)
      .PreferredWidthType = wdPreferredWidthPoints
      .PreferredWidth = InchesToPoints(1.6)
   End With
Next
End Sub
will change every table so that column 2 is 1.6 points wide. So, again if you know what your structure is to be for each table (and each table is to be identical!!)...
Code:
Sub ChangeAllTables()
Dim oTable As Table
For Each oTable In ActiveDocument.Tables()
   With oTable
       With .Columns(1)
           .PreferredWidthType = wdPreferredWidthPoints
           .PreferredWidth = InchesToPoints(0.8)
       End With
       With .Columns(2)
           .PreferredWidthType = wdPreferredWidthPoints
           .PreferredWidth = InchesToPoints(1.6)
       End With
       With .Columns(3)
           .PreferredWidthType = wdPreferredWidthPoints
           .PreferredWidth = InchesToPoints(0.4)
       End With

Next
End Sub
would change all tables to:

Column 1 0.8
Column 2 1.6
Column 3 0.4

Be careful though! If you are doing this, make sure you set the width for all the columns.

Gerry
 
There appears to be a way to sort of set defaults. I opened a new document that is inherently linked to normal.dotm. Bring up the "Insert Table" dialog and fill in what you would like your default values to be. It normally comes up as 5 columns, 2 rows, and Fixed Column Width of "Auto". If you click on the "Remember information for future tables" box at the bottom of the dialog and say OK, you get a table created as expected.
In limited playing around, I got out of that document without saving anything and opened a new document. When I again ran the "Insert Table" dialog it started off by displaying the changed information that I had put in while I had the first document open.
Since this is visible to the user, it would appear to allow you to reset your defaults as desired, and you can always set up a unique table by adjusting the values in the dialog for the specific arrangement you want just like you would have if you had never "remembered" anything.
The big key from my perspective is getting a lock on the fixed column width with something other than Auto.
Now that we've figured that out, I'll probably mumble at some point in the future about everything locking to a particular width because I will have forgotten what I did to cause it.
This still leaves tables that have already been created, but there was already a known way to set them straight.

Thank you to all who offered suggestions.

Al..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top