Insert line break in MS word table

10,290

Solution 1

This works in Word 2010, you'll need to have the correct cell etc. selected:

Selection.TypeText Text:=Chr(11)

/edit/

How about this? Forgive the use of Selection to get the range, I know you don't like it but it was the quickest way for me to test. You can use your own way to get the range.

Sub Macro3()

Dim oRange As Range
    ' Add your own range selection code here!
    Set oRange = Selection.Range
    oRange.InsertAfter (Chr(11))


End Sub

Solution 2

Try shift + enter - I think that does the trick.

Share:
10,290

Related videos on Youtube

Jamie
Author by

Jamie

Updated on June 04, 2022

Comments

  • Jamie
    Jamie almost 2 years

    I'm trying to insert a line break into a table cell. So far I've been trying to manipulate the range of the cell, but am either getting errors or causing my text to go into subsequent rows or outside of the table.

    How would I insert a line break into a table cell?

    (Using macros, there is apparently a way to do it with Selection, but I'd rather avoid that if possible)

    (Things I have that don't work: range.InsertParagrah, range.InsertParagraphAfter, range.Text = "\r\n", range.InsertBreak(wdLineBreak))

    • Eddy
      Eddy almost 13 years
      What have you got that isn't working?
  • Jamie
    Jamie almost 13 years
    This is what I plan to resort to if there aren't better solutions, but I'd much rather not mess with Selections if at all possible. Still, it's a solution
  • Jamie
    Jamie almost 13 years
    Strangely, both of them cause the remaining output to be outputted in the next row or outside of the table.
  • Jamie
    Jamie almost 13 years
    Actually, it turns out that this works, and a whole bunch of other things work. I was just accidentally looking at another character (I think the row-ending character or paragraph-ending character) that caused errors. Basically I used to have "range = cell.Range" but I had to add the line "range.SetRange(range.Start, range.End - 1)". note to self: learn to read documentation...
  • oleksa
    oleksa about 7 years
    thanks for a hint. I've just managed to apply this fix in my code. However I'd like to note that Chr(11) should be inserted when text is in the cell already. If text contains Chr(11) and is converted to the table (like with Range.ConvertToTable) then it is treated like new row break.