Hi Guys,
I am using MacOS High Sierra, Version 10.13 and Script Editor 2.10.
I have a word file with Tables. The Table Header Cells contains multiple lines in each.
some cell may be 2 lines, some may be 4 and some may be 5 etc.,
What I need is to insert some text at the end of every line in all cells.
I googled for many days, but Unluck. I just got script (below) to loop the cells.
Any help may be appreciated.
tell application "Microsoft Word"
set tRow to row 1 of selection
set ccount to count every cell of row 1 of selection
if tRow is not {} then -- the selection is in the table
repeat with i from 1 to ccount
set thecell to content of text object of cell i of tRow
display dialog thecell
set i to i + 1
end repeat
end if
end tell
Thanks in advance,
Mathew
You can do it like this:
Edit: Sorry, I missed the bit about needing to insert text at the end of every line. Corrected my code to account for that.
tell application "Microsoft Word"
try
set headerCells to every cell of (row 1 of table 1 of selection)
repeat with aCell in headerCells
execute find (find object of (text object of aCell)) find text "^p" replace with "!!!^p" replace replace all
insert text "!!!" at end of (text object of aCell)
end repeat
on error
display dialog "selection is not in a table"
end try
end tell
Hi Roosterboy,
Thanks for your kind reply.
Your script replace the “^p” with “!!!^p”. If “^p” is not in a cell, it inserts “!!!” at the end of the each cell. This script will helpful for me. But not in current situation.
Sorry, If I not explained it clearly. What I expect is, For example, If a cell’s full content object is “AAAA aaa BBB bbb CCC CCc” whereas it looks like in visual as below (something like wrap text)
AAAA aaa
BBB bbb CCC
CCc
The Output should be
AAAA aaa !!!^p
BBB bbb CCC !!!^p
CCc !!!^p
Sorry for the inconvenience.
Mathew
It… does that?
Before:
After:
Ah, wait, my test data has explicit paragraph breaks in the text. Does the data you are working with wrap because the column is constrained to a specific width or does it have explicit paragraph breaks in it?
If the former, then I’m not sure there is a way to do what you want.
HI Roosterboy,
Yes, column is constrained to a specific width. It doesn’t have explicit paragraph breaks in it.