A family of Microsoft word processing software products for creating web, email, and print documents.
This works:
tell application "Microsoft Word"
activate
selection clear formatting
end tell
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
A family of Microsoft word processing software products for creating web, email, and print documents.
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.
This works:
tell application "Microsoft Word"
activate
selection clear formatting
end tell
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.
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.
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
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.