Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2012, 11:32 AM
knightmetal knightmetal is offline Formatting all tables Windows 7 32bit Formatting all tables Office 2007
Novice
Formatting all tables
 
Join Date: Sep 2012
Posts: 2
knightmetal is on a distinguished road
Default Formatting all tables

Hello,



I have about 60 tables in a document I'm working on, I need to apply AutoFit to all of them but I'm having several difficulties.

The first problem I found was that I didn't know how to select all the tables at once, I managed to do that using the Visual Basic method and a second possibility is to download KuTools which lets you select the tables by just clicking one button, the results are pretty much the same.

Now the problem is that AutoFit is disabled when all the tables are selected, it normally works for one but not for multiple tables. Does anybody have any workaround solution? thanks.
Reply With Quote
  #2  
Old 09-10-2012, 02:53 PM
knightmetal knightmetal is offline Formatting all tables Windows 7 32bit Formatting all tables Office 2007
Novice
Formatting all tables
 
Join Date: Sep 2012
Posts: 2
knightmetal is on a distinguished road
Default

Well, I'm replying to myself, just for people having the same problem in the future

Code:
Sub Macro1()
'
Dim pT As Word.Table
For Each pT In ActiveDocument.Tables
pT.PreferredWidth = MillimetersToPoints(170)
Next
MsgBox "done"
End Sub
170 is the width of the tables given in mm.

Last edited by macropod; 09-10-2012 at 10:42 PM. Reason: Added code tags & formatting
Reply With Quote
  #3  
Old 09-10-2012, 10:53 PM
macropod's Avatar
macropod macropod is offline Formatting all tables Windows 7 64bit Formatting all tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi knightmetal,

Your macro doesn't actually apply the autofit attrinbute. Rather, it sets a preferred width which will remain fixed regardless of changes to margins etc.

A true autofit macro is more like:
Code:
Sub Autofit()
Application.ScreenUpdating = False
Dim Tbl As Table
For Each Tbl In ActiveDocument.Tables
  Tbl.AutoFitBehavior (wdAutoFitWindow)
  Tbl.AllowAutoFit = True
Next
Application.ScreenUpdating = True
Application.ScreenRefresh
MsgBox "Done", vbOKOnly
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting all tables Macro for selecting pages and formatting of tables ubns Word VBA 25 08-15-2012 11:48 PM
Formatting all tables Formatting multiple tables and columns efficiently? table_column Word Tables 1 07-02-2012 05:55 PM
Another Case of Automatic/Zombie Formatting of Tables MKummerfeldt Word Tables 0 10-31-2011 10:40 AM
Formatting all tables Copy table cell formatting across multiple cells / tables pakistanray Word Tables 2 10-31-2011 08:07 AM
Whacked formatting in tables (2007) Roscoe Word Tables 6 06-11-2010 02:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft