Thread: [Solved] Trim spaces from table cells
View Single Post
 
Old 09-04-2018, 04:21 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

They're just ordinary spaces. You can't clean them up by the normal centring/uncentring methods in VBA but you can clean them up with code like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, Cll As Cell
For Each Tbl In ActiveDocument.Tables
  For Each Cll In Tbl.Range.Cells
    With Cll.Range
      If Len(.Text) > 2 Then
        Do While .Characters.First.Text = " "
          .Characters.First.Text = vbNullString
        Loop
      End If
      If Len(.Text) > 2 Then
        Do While .Characters.Last.Previous.Text = " "
          .Characters.Last.Previous.Text = vbNullString
        Loop
      End If
    End With
  Next
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote