Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2018, 03:08 PM
jeffreybrown jeffreybrown is offline Trim spaces from table cells Windows Vista Trim spaces from table cells Office 2007
Expert
Trim spaces from table cells
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Trim spaces from table cells

After converting a pdf to Word, some of the tables have a space before some of the context in the tables.

I would guess it's a space as I can backspace it out, but noticed if I apply Alignment Center, the spaces disappear. I recorded a macro to get that code, but when running the macro the behavior is not the same as when the Align Center is manually applied.



I've use the macro on this board for cleaning up pasted text from a pdf, but that doesn't seem to do anything for this.

1) Can the cells of the table be trimmed?
2) Is there a way in the immediate window to figure out what these spaces are? Maybe showing the code for the mark?
Attached Files
File Type: docx test.docx (13.0 KB, 9 views)
Reply With Quote
  #2  
Old 09-04-2018, 04:21 PM
macropod's Avatar
macropod macropod is offline Trim spaces from table cells Windows 7 64bit Trim spaces from table cells Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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
  #3  
Old 09-04-2018, 07:36 PM
jeffreybrown jeffreybrown is offline Trim spaces from table cells Windows Vista Trim spaces from table cells Office 2007
Expert
Trim spaces from table cells
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thanks again Paul. Works great.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table of contents - unwanted spaces MichyX Word 7 11-02-2017 02:12 PM
Trim spaces from table cells How to remove blank spaces between rows in a table, Jamal NUMAN Word 2 04-28-2017 12:59 PM
How to remove spaces from Cells which are at the end of value? LearnerExcel Excel 2 12-19-2016 01:10 PM
How can I delete spaces & lines in a table cell mrayncrental Word VBA 3 10-20-2014 07:09 PM
Trim spaces from table cells Columns lines in table have spaces and indents in the borders lukester Word Tables 3 07-11-2012 07:01 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:31 AM.


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