Set Highlight of selected text

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Tee
Posts: 1
Joined: 17 Oct 2018, 19:44

Set Highlight of selected text

17 Oct 2018, 19:53

Hello Everyone,

Hope someone will be able to help

I want to make hot-keys to highlight onlt the selected text with f10, f11, f12
I' having an issue with the highlight, it highlight all the text and it is staying on after it applies the highlight
Is there a way to only highlight the selected and turn it off after it applies the desired color to highlight with?

Code:

; AutoHotkey_L

F10:: ComObjActive("Word.Application").ActiveDocument.Range.HighlightColorIndex := 2
F11:: ComObjActive("Word.Application").ActiveDocument.Range.HighlightColorIndex := 3
F12:: ComObjActive("Word.Application").ActiveDocument.Range.HighlightColorIndex := 4
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Set Highlight of selected text

17 Oct 2018, 20:22

For highlighting, something like this:

Code: Select all

F10:: ComObjActive("Word.Application").Selection.Range.HighlightColorIndex := 2
F11:: ComObjActive("Word.Application").Selection.Range.HighlightColorIndex := 3
F12:: ComObjActive("Word.Application").Selection.Range.HighlightColorIndex := 4
Possibly, to turn off the colour:

Code: Select all

F10::
F11::
F12::
oWd := ComObjActive("Word.Application")
InStr(A_ThisHotkey, "10") ? (vCol := 2)
: InStr(A_ThisHotkey, "11") ? (vCol := 3)
: InStr(A_ThisHotkey, "12") ? (vCol := 4) : 0
oWd.Selection.Range.HighlightColorIndex := vCol
oWd.Options.DefaultHighlightColorIndex := 0
oWd := ""
return
Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], OrangeCat, scriptor2016 and 119 guests