Hi Jerome
at a long shot, I'd say you are trying
to add a VbCrLf after a cell's range,
which doesn't work as expected.
Sub Test004()
With ActiveDocument.Tables(1).Cell(1, 2).Range
.Characters.Last.InsertBefore vbCrLf
End With
End Sub
For the pecularities of the end-of-cell mark
Jay Freedman explained:
Quote:
VBA itself seems to be confused about the nature of the cell marker.
In some places it treats it as one character and in other places as
two. Try running this little macro on a document that contains a
table:
Sub demo()
Dim oRg As Range
Dim msg As String
Set oRg = ActiveDocument.Tables(1).Cell(1, 1).Range
msg = "Cell including marker" & vbCr & _
"length = " & Len(oRg.Text) & vbCr & _
"Chr(" & Asc(Mid(oRg.Text, Len(oRg.Text) - 1, 1)) & _
"), Chr(" & Asc(Right(oRg.Text, 1)) & ")"
MsgBox msg
oRg.MoveEnd Unit:=wdCharacter, Count:=-1
msg = "Cell excluding marker" & vbCr & _
"length = " & Len(oRg.Text)
MsgBox msg
End Sub
You can see in the first messagebox that the cell marker is two
characters, Chr(13) and Chr(7) in that order. Then the MoveEnd method
moves the range's end *one* character to the left, but the range is
now *two* characters shorter than before.
When you pull the contents of a cell's range into a VBA string
variable, you'll always see the two separate characters at the end.
When you deal with the range within the document itself, though, the
marker behaves as one character.
Unquote.
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"