Reputation: 33
Pasting html data into a Word table cell.it creates carriage return end of table cell.How to remove carriage return only the end of table cell.
Upvotes: 1
Views: 4776
Reputation: 13515
As will the following - for all terminating paragraph marks in all cells in all tables in the document:
Dim Tbl As Table, TblCell As Cell, Rng As Range
For Each Tbl In ActiveDocument.Tables
For Each TblCell In Tbl.Range.Cells
Set Rng = TblCell.Range
With Rng
.End = .End - 1
Do While .Characters.Last = vbCr
.Characters.Last = vbNullString
Loop
End With
Next
Next
It's better, though, not to insert them in the first place and, until we see the OP's code, we can't advise on how best to achieve that.
Upvotes: 0
Reputation: 33
The following will remove a ¶ before the end of cell marker
Dim rngcell As Range
Set rngcell = Selection.Cells(1).Range
rngcell.Start = rngcell.End - 2
rngcell.Text = Replace(rngcell.Text, vbCr, "")
Upvotes: 1
Reputation: 578
This will remove the Carriage returns and resize the rows
Public Sub removeCR(ByRef rng As Word.Table)
For Row = 1 To tbl.Rows.Count
For col = 1 To tbl.Columns.Count
Call tbl.Cell(Row, col).Select
With Selection
If Len(.Text) > 2 Then
If Mid(.Text, Len(.Text) - 2, 1) = vbCr Then
Let .Text = Left(.Text, Len(.Text) - 3) & chr$(7)
End If
End If
End With
Next col
Let tbl.Rows(Row).HeightRule = wdRowHeightAuto
Next Row
End Sub
if you have to remove multiple of the carriage returns, or have to deal with linefeeds then you may consider a modification to the innermost If
statement such as
While Mid(.Text, Len(.Text) - 2, 1) = vbCr Or _
Mid(.Text, Len(.Text) - 2, 1) = vbLf
Let .Text = Left(.Text, Len(.Text) - 3) & Chr$(7)
Wend
Upvotes: 0