2013-09-24, 00:43 #1
- Join Date
- Sep 2013
- Thanked 0 Times in 0 Posts
Macro for table width in percentage
I have a huge financial file for formatting and this has lot of tables and different column width through out the file for eg.
3 column width table consists of :
70 % + 15% + 15% respectively as table width (I need the width in percentage only and not in points or cm or mm)
4 column width:
55% + 15% + 15% + 15%
5 column width:
40% + 15% + 15% + 15% +15%
6 column width:
40% + 12% +12% +12% +12% +12% and so on and I need upto around 9 colcumn width where the 1st column least size can be 28% and cannot go less than that but the next column width can vary.
The width need to be measured in percentage because when uploaded on webpage as HTML file the table should expand accordingly
Thank you in advance
Subscribe to our Windows Secrets Newsletter - It's Free!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!
+ Get this BONUS — free!
Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!
2013-09-30, 17:30 #2
- Join Date
- May 2002
- Canberra, Australian Capital Territory, Australia
- Thanked 179 Times in 165 Posts
You could try something like:
Sub TableColumnFormat() Dim Tbl As Table, i As Long, Wdth As Single For Each Tbl In ActiveDocument.Tables With Tbl .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 100 Wdth = 100 / (.Columns.Count + 3) For i = 2 To .Columns.Count With .Columns(i) .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = Wdth End With Next With .Columns(1) .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = Wdth * 4 End With End With Next End SubCheers,
[MS MVP - Word]