pastes the text that is already in the clipboard in Microsoft Word.
As the text is being pasted, remove all formatting.
Select the text that was just pasted in word and just change the paragraph style to one called CODE I have in my Word.
This CODE style has the option “Don’t add space between paragraphs of the same style” turned on, but when I paste unformatted text this option is always off. So, as a step 4, I need this option to be applied to the pasted text.
So far I have accomplished this:
tell application "Microsoft Word"
paste special (text object of selection) data type paste text
end tell
This pastes text without formatting and covers steps 1 and 2.
I think the simpest way to do it is to make the style change before you paste in the text. OMM, this also preserves the spacing.
tell application "Microsoft Word"
activate
set myWord to the clipboard
tell text object of the selection
set style to style "CODE"
end tell
paste special (text object of selection) data type paste text
end tell
That’s odd. There seems to be a missing word: "Word style “CODE”
Try below.
Yes, I copied and pasted from another script and didn’t clean it all up.
tell application "Microsoft Word"
activate
tell text object of the selection
set style to Word style "CODE"
end tell
paste special (text object of selection) data type paste text
end tell
→ Mac OS Version 11.6.8 (20G730)
→ Script Debugger 8.0.5 (8A61)
→ Microsoft Word for Mac 16.67
tell application "Microsoft Word"
set style of (text object of the selection) to "CODE"
paste special (text object of selection) data type paste text
end tell