View Single Post
 
Old 09-30-2014, 07:17 PM
treva31 treva31 is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Sep 2014
Posts: 2
treva31 is on a distinguished road
Default Losing formatting using .Text to replace

Hi,

I have this little sub that removes leading and trailing spaces from text in cells of all my tables.

It works great but it turns any coloured text to black.

Is there a way to keep the formatting?

Thanks.


Code:
Sub RemoveSpaces() 
    Dim oRng As Range 
    Dim oTable As Table 
    Dim acell As Cell 
    For Each oTable In ActiveDocument.Tables 
        With oTable 
            For Each acell In oTable.Range.Cells 
                Set oRng = acell.Range 
                oRng.End = oRng.End - 1 
                oRng.Text = Trim(oRng.Text) 
            Next acell 
        End With 
    Next oTable 
End Sub

Last edited by macropod; 09-30-2014 at 09:15 PM. Reason: Added correct code tags & formatting
Reply With Quote