Macro to Highlight the Selected Text in Microsoft Word?

I'm trying to trigger the highlight function in word, via a keyboard trigger. I don't like having to use the mouse for a common function. I'm being stymied because MS doesn't consider highlighting a command that I give a shortcut to. Is there a clever way to use the ribbon? (Short of recording a macro).

Hey Mark,

Yep. Look here:

A working macro is:

Sub Highlight_Selected_Text()
    CurColor = Options.DefaultHighlightColorIndex
    Application.ActiveDocument.Application.Options.DefaultHighlightColorIndex = CurColor
    Selection.Range.HighlightColorIndex = CurColor
End Sub

BUT – you don't have to write a macro. The highlight command is available in the Word-Menu-Bar > Tools > Customize Keyboard...

You can directly assign it a keyboard shortcut in Word.

Other choices are:

-Chris

Chris - thanks I had forgotten to look on StackOverflow. Funny since I’ve been back on a MacOS my StackOverflow brain seems to have been disabled.

I wasn’t able to find the highlight command in the customize keyboard, I will check again in a few minutes.

FWIW A few minutes of fighting with word helped me find it in the Customize Keyboard list. Danke - Mark

1 Like

Hi,

I had the same need and just found the AppleScript from here:

Here is the script:

tell application "Microsoft Word"
	set {selection start:startIndex, selection end:endIndex} to selection
	set theRange to create range active document start startIndex end endIndex
	set highlight color index of theRange to yellow
end tell

In case you may need, this is how to change the font color of the selected text, adapted from the script above:

tell application "Microsoft Word"
	set {selection start:startIndex, selection end:endIndex} to selection
	set theRange to create range active document start startIndex end endIndex
	set color index of font object of theRange to red
end tell
1 Like