0

I have a string with a number, looking like this:

"12345678-123"

I want to add a linefeed (the thing you get by pressing [SHIFT] + [ENTER]) before the dash "-".

It keeps adding a carriage return. This is my code:

sSomeString = Replace(sSomeString, "-", vbLf & Chr(30)) 'Chr(11) does not work ether - Chr(30) is the char for the dash, that does not break

ActiveDocument.Tables(iTableIndex).Cell(.Rows.Count, 4).Range.Text = sSomeString

I googled and so far it says everywhere to use ether vbLf or Chr(11). Any ideas?

// Problem solved:

My code didn't run correctly cause I was not using the Char(30), so Word created a Linebreak with the character "-"

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
user2871190
  • 241
  • 2
  • 5
  • 19

1 Answers1

1

Word uses the vertical tab (character code 11) for line breaks. So you'll want something like this:

sSomeString = Replace(sSomeString, "-", Chr(11) & Chr(30))

I don't know if Microsoft makes this readily available. However, you can always insert a line break in Word (Shift+Enter), then use VBA to examine the character code.

Zack
  • 2,220
  • 1
  • 8
  • 12