baset
03-03-2016, 12:05 PM
I'm using this macro to remove space at end of table cell; it works fine but the format of text changed; WHY ?
Sub CleanCellEndSpaces()'Define variables (that is, containers for information)
Dim aTable As Table
Dim aCell As Cell
Dim aRow As Row
Dim aColumn As Column
Dim aRange As Range 'A specific area of the document
Dim aLen As Integer 'A number
Dim LastChar As String 'A string of characters (text)
Dim Tracking As Boolean 'True or False
Tracking = ActiveDocument.TrackRevisions 'Get setting of revision tracking
ActiveDocument.TrackRevisions = False 'Turn off revision tracking
On Error Resume Next 'In case of tables with "vertically merged" cells
'Cycle through tables, rows, and cells
For Each aTable In ActiveDocument.Tables
For Each aRow In aTable.Rows
For Each aCell In aRow.Cells
CheckAgain:
Set aRange = aCell.Range 'Set aRange variable to the contents of the current cell
aRange.End = aRange.End - 1 'Don’t include the end-of-cell marker
aLen = Len(aRange.Text) 'Get the length of the cell’s text
aString = aRange.Text 'Assign the text to a variable
LastChar = Right(aString, 1) 'Get the last character of the text
If LastChar = " " Then 'If the last character is a space
aRange.Text = Left(aRange.Text, aLen - 1) 'Set the text to be itself minus the trailing space
GoTo CheckAgain 'Go back and check for another space (there may be several)
End If
Next aCell
Next aRow
Next aTable
ActiveDocument.TrackRevisions = Tracking 'Set revision tracking back to its original state
End Sub
From:
15549
To:
15550
Sub CleanCellEndSpaces()'Define variables (that is, containers for information)
Dim aTable As Table
Dim aCell As Cell
Dim aRow As Row
Dim aColumn As Column
Dim aRange As Range 'A specific area of the document
Dim aLen As Integer 'A number
Dim LastChar As String 'A string of characters (text)
Dim Tracking As Boolean 'True or False
Tracking = ActiveDocument.TrackRevisions 'Get setting of revision tracking
ActiveDocument.TrackRevisions = False 'Turn off revision tracking
On Error Resume Next 'In case of tables with "vertically merged" cells
'Cycle through tables, rows, and cells
For Each aTable In ActiveDocument.Tables
For Each aRow In aTable.Rows
For Each aCell In aRow.Cells
CheckAgain:
Set aRange = aCell.Range 'Set aRange variable to the contents of the current cell
aRange.End = aRange.End - 1 'Don’t include the end-of-cell marker
aLen = Len(aRange.Text) 'Get the length of the cell’s text
aString = aRange.Text 'Assign the text to a variable
LastChar = Right(aString, 1) 'Get the last character of the text
If LastChar = " " Then 'If the last character is a space
aRange.Text = Left(aRange.Text, aLen - 1) 'Set the text to be itself minus the trailing space
GoTo CheckAgain 'Go back and check for another space (there may be several)
End If
Next aCell
Next aRow
Next aTable
ActiveDocument.TrackRevisions = Tracking 'Set revision tracking back to its original state
End Sub
From:
15549
To:
15550