Word 'styles' utlise paragraph formatting in addition to text formatting, so I am trying to create a macro where I copy four different strings to the clipboard, and it opens Word and pastes them with the correct style applied. I imagine this can only be done with applescript, if Word supports that. Can anybody give me an idea if it can be done before I start down another automation rabbit hole?
I could do the text formatting with KM, but say adding extra space after the paragraph is only in word. I'm using 'Heading 1' 'Heading 2' etc.
I'm not having a problem with the copying and pasting, just the word styles element (so far!)
If you want to use actual Word Styles (as opposed to text formatting by KM), then you will need to paste each string into Word, and then apply the Word style using either VBA or AppleScript. Since this is totally within Word, I would first try Word VBA, since you can easily run the Word Macro recorder and manually enter the steps to create the VBA Macro.
As you noted, Word Styles are applied to paragraphs, so I assume each of your strings will be a paragraph. So, after you paste each string (which does NOT end in a new line character), just run a Word VBA Macro that applies the style. You may want to use AppleScript to either run the macro, or just execute the same command as the VBA shown below.
The VBA is very simple. I just recorded this in Word 2011:
' Apply_Style Macro
Selection.Style = ActiveDocument.Styles("Intense Quote")
It took some work but I got it to work. Turns out the best way seems to be to set the style first, and then paste the text, rather than pasting and then trying to style it, due to carriage returns and paragraphs. Which you predicted of course with your post.