Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-20-2018, 02:53 PM
macropod's Avatar
macropod macropod is offline Table column width wrong - unless macro paused!? Windows 7 64bit Table column width wrong - unless macro paused!? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Far more efficient:
Code:
Sub Test2()
Application.ScreenUpdating = False
Dim Tbl As Table
Const text_a As String = "A text"
Const text_b As String = "A longer text to make the column need more width"
Const text_c As String = "More text"
 
Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=1, NumColumns:=3, _
  DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=False)
With Tbl
  .ApplyStyleHeadingRows = True
  .ApplyStyleLastRow = True
  .ApplyStyleFirstColumn = True
  .ApplyStyleLastColumn = True
  .AllowAutoFit = False
  .PreferredWidthType = wdPreferredWidthPoints
  .PreferredWidth = CentimetersToPoints(17.5)
  .LeftPadding = 0
  .RightPadding = 0
  With .Cell(1, 1)
    .PreferredWidthType = wdPreferredWidthPoints
    .PreferredWidth = CentimetersToPoints(3.2)
    .Range.Text = text_a
  End With
  With .Cell(1, 2)
    .PreferredWidthType = wdPreferredWidthPoints
    .PreferredWidth = CentimetersToPoints(13.4)
    .Range.Text = text_b
  End With
  .Cell(1, 3).Range.Text = text_c
End With
Application.ScreenUpdating = True
Application.ScreenRefresh
MsgBox ("OK")
End Sub
Note: One wouldn't ordinarily bother with Application.ScreenRefresh, but you seem concerned to show the table in its final form before the message-box displays.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
create fields with multiple lines - fix column width in table expert4knowledge Word 4 02-14-2014 01:06 PM
Table column width wrong - unless macro paused!? Inserted AutoText table incorrectly formatted - unless macro paused! Smallweed Word VBA 4 01-16-2014 03:15 PM
Table column width wrong - unless macro paused!? Column Width keeps changing alsmith Word Tables 1 05-25-2013 02:09 AM
Table column width wrong - unless macro paused!? Word 2012: Change column width changes table width OpfinnarJocke Word Tables 1 09-22-2012 04:03 AM
Table column width wrong - unless macro paused!? Column width markg67 Word 2 06-07-2010 07:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:48 AM.


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