Carriage return in a word table

  • Thread starter Carriage return in a word table
  • Start date
C

Carriage return in a word table

Hello,

I've a table already created and I'm replacing tag created by myself by
variables
Some tags are in a table and I want to put more than one line in these tags.

I've tried to add vbcrlf but it's not working inside a table

Could you please help me?

Regards

Jerome
 
H

Helmut Weber

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top