I would like to find a way to change the style to heading1 of a particular text string that I'm adding in an MS Word document using Applescript, but after hours of searching, and looking at the dictionary, I can't find a way to to it. Something like this:

    tell application "Microsoft Word"
    tell active document
        set ContTemp to content of text object
        set StartRange to (count of ContTemp) - 1
        set endrange to StartRange
        set theRange to create range start StartRange end endrange
        set style of format of theRange to style heading1
        set content of theRange to StringVar
    end tell
end tell

But it generates an error at "set style of format of theRange. . . ". Removing that single lines works to add the text StringVar (a simple text string) into the Word document. But I can't style it, and I need to have it set to heading1.

Thanks for the help!!


1 Answer 1


If you open the Microsoft Word dictionary in Script Editor you will see that a range does not have an attribute format, only an attribute style so the correct line is set style of theRange to style heading1.

After that your code complains that StringVar is not defined so I assume you are setting it before the code you have given us.

  • Thank you! Looking at the dictionary is quite a maze, with a large number of variations of style attributes, so after looking at it over and over, I missed it! (Yes, the string variable is set in the earlier part of the script.) Your correction worked beautifully. Thanks!!
    – MBUST
    Apr 15, 2018 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .