Share via

how do I clear a formatting style from Applescript?

Anonymous
2024-04-06T21:52:17+00:00

This Applescript works:

tell application "Microsoft Word" 

tell paragraph format of selection to set style to style normal

end tell

How do I write a style-setter that does the equivalent of "clear formatting"?

The goal is to use a touchbar button to reduce the number of times I need to click to show the styles panel. In general I don't want to see that panel; it takes up too much screen width that I need for other things.

Microsoft 365 and Office | Word | For education | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

14 answers

Sort by: Most helpful
  1. Jim G 134K Reputation points MVP Volunteer Moderator
    2024-04-08T17:11:41+00:00

    This works:

    tell application "Microsoft Word"
    activate
    selection clear formatting
    end tell
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Stefan Blom 342.4K Reputation points MVP Volunteer Moderator
    2024-04-07T19:05:28+00:00

    I checked the Customize Keyboard dialog box first, too. :-) ClearParagraphAllFormatting and the other functions are not present as built-in commands in Word for Win, either.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Bob Jones AKA CyberTaz MVP 436K Reputation points
    2024-04-06T23:11:16+00:00

    PS: You may also be interested in the default keyboard shortcut which applies Normal Style, Shift+Command+N.

    Note that for all of these whether first selecting the text is necessary depends on whether the formatting to be removed was applied directly or by a valid Style.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2024-04-07T00:31:45+00:00

    Thanks, Bob. You are right that I want the same effect as clicking on that Styles Pane Clear Formatting button, but the goal is to tie the action to a touchbar button. I think that I need an Applescript for that.

    I certainly do not want to display the styles pane – it gets in my way, and then I'd have to move off the keyboard to click items in it. Mouse actions suit for occasional use but not for heavy editing jobs where the client has sent a mishmash of styles plus custom variations like little indent shifts or a few words with a weird tracking change (I suspect that much of this comes from copying and pasting from PDFs and web pages but no one's ever confessed to me).

    "Clear formatting" appears in the Applescript dictionary for Word but I haven't figured out how to apply it to the paragraph – experiments so far have only made Word crash.

    "clearFormatting" doesn't make it crash but it also doesn't appear to do anything (when called by Applescript). I suspect that it's because I'm calling it wrongly. Neither of the following appear to do anything to a Normal paragraph containing a few bolded, underlined, and italicised irregularities.

    tell selection to ClearFormatting
    
    tell paragraph of selection to ClearFormatting
    

    Was this answer helpful?

    0 comments No comments
  5. Bob Jones AKA CyberTaz MVP 436K Reputation points
    2024-04-06T22:42:02+00:00

    Perhaps I'm reading into your message but it sounds like you may be under the impression that you need to display the Styles Pane in order to simply clear formatting. If so there is no need for any sort of script. Just assign a Word keyboard shortcut to the ClearFormatting command or to the ClearAllFormatting command: Both do basically the same thing.

    If I'm misunderstanding the requirement please provide a more detailed explanation.

    Including Word & macOS Version Numbers in your reply may be useful.

    Was this answer helpful?

    0 comments No comments