COM Word highlighting toggle help

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

COM Word highlighting toggle help

13 May 2024, 16:59

Hi, noob here.
I'm currently using this to change any word yellow:

Code: Select all

NumpadAdd:: {
	; SendEvent("!+h")   ; highlight
	w := ComObjActive("Word.Application")
	if (SubStr(w.Selection.Range.Text, -1) = ' ')                                  ; 
		w.Selection.SetRange(w.Selection.Range.Start, w.Selection.Range.End - 1)   ; these two lines deselect the trailing space
	w.Selection.Range.HighlightColorIndex := 7  ; yellow
	sound_pop()
	w.selection.collapse(0)
}
Can someone modify this so that it's a yellow/no colour toggle?
Thanks!
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: COM Word highlighting toggle help

13 May 2024, 19:25

Code: Select all

NumpadAdd:: {
	; SendEvent("!+h")   ; highlight
	w := ComObjActive("Word.Application")
	if (SubStr(w.Selection.Range.Text, -1) = ' ')                                  ; 
		w.Selection.SetRange(w.Selection.Range.Start, w.Selection.Range.End - 1)   ; these two lines deselect the trailing space
	w.Selection.Range.HighlightColorIndex := w.Selection.Range.HighlightColorIndex = 7 ? 0 : 7  ; 7 = yellow
	sound_pop()
	w.selection.collapse(0)
}
robinson
Posts: 214
Joined: 12 Sep 2019, 20:28

Re: COM Word highlighting toggle help

13 May 2024, 19:27

@boiler Beautiful. Thanks!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, robinson and 38 guests