slyguy
03-23-2015, 02:25 PM
I had to strip some characters from right side of table cells as it causes text in the table to run in on our conversion. This works, except, it causes formatting to get dropped. Is there any way to preserve formatting?
TIA?
This is what I have...
...
'loop through all tables
For itable = 1 To ActiveDocument.Tables.Count
'loop through all rows
For Row = 1 To ActiveDocument.Tables(itable).Rows.Count
'loop through all cols
For Col = 1 To ActiveDocument.Tables(itable).Columns.Count
'grab text
strCellText = ActiveDocument.Tables(itable).Cell(Row, Col).Range.Text
If Err.Number = 0 Then
Dim a, b
a = Chr(9) & Chr(13) & Chr(7)
b = Chr(7)
If Right(strCellText, 3) = a Then
strCellText = Replace(strCellText, a, b)
ActiveDocument.Tables(itable).Cell(Row, Col).Range.Text = strCellText
End If
Else
Err.Clear
End If
Next 'next/End Col loop
Next 'next/End Row loop
Next 'next/end Table loop
TIA?
This is what I have...
...
'loop through all tables
For itable = 1 To ActiveDocument.Tables.Count
'loop through all rows
For Row = 1 To ActiveDocument.Tables(itable).Rows.Count
'loop through all cols
For Col = 1 To ActiveDocument.Tables(itable).Columns.Count
'grab text
strCellText = ActiveDocument.Tables(itable).Cell(Row, Col).Range.Text
If Err.Number = 0 Then
Dim a, b
a = Chr(9) & Chr(13) & Chr(7)
b = Chr(7)
If Right(strCellText, 3) = a Then
strCellText = Replace(strCellText, a, b)
ActiveDocument.Tables(itable).Cell(Row, Col).Range.Text = strCellText
End If
Else
Err.Clear
End If
Next 'next/End Col loop
Next 'next/End Row loop
Next 'next/end Table loop