Apple Script and line breaks in Excel

Hi all,

I have came across an issue in which I would like your help.

When I am executing this script:

set abc to "Line 1: This is the first line.\rLine 2: This is the second line.\r\r\linefeedAnother one third line."

tell application "Microsoft Excel"
	activate
	select sheet "Sheet2"
	select range "A1"
	set value of active cell to abc
end tell

the text in Excel is not shown with the correct formatting. The line breaks unfortunately are not shown.

So, I would like to have it shown as:

but instead it is shown as:

However, if I double click on the cell, the correct formatting is shown.

And imagine now that there are hundreds of cells that I have to update.

Is there any workaround or any script to simplify this process?

Thank you in advance.

Try this:

set abc to "Line 1: This is the first line." & linefeed & "This is the second line." & linefeed & linefeed & linefeed & " Another one third line."

tell application "Microsoft Excel"
	activate
	select sheet "Sheet1"
	select range "A1"
	set value of active cell to abc
end tell

Your problem is that you put a backslash in front of ‘linefeed’. Either use the constant sans backslash (linefeed) outside of quotes and bracketed by ampersands, or use its value (\n) the way you used the value for carriage returns (\r).

FWIW, I think Excel prefers carriage returns but I vaguely recall that there is something quirky about it (as in a decision that MS made aeons ago). So you may get different results depending upon which you use. You may have to experiment.

Anyway, it could look like this:

set abc to "Line 1: This is the first line.\rLine 2: This is the second line.\r\r\nAnother one third line."

estockly of course, provides the alternate form.

Thank you both for your replies!

I followed the solution from estockly and it worked!

Indeed Mockman I had an error in the original code. Sometimes it is in front of our eyes but we are blind! But thanks anyway!