Highlight text in the middle of a line using COM in MS Word

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ShubhamM
Posts: 38
Joined: 08 Nov 2017, 21:38

Highlight text in the middle of a line using COM in MS Word

Post by ShubhamM » 01 Mar 2022, 19:17

Hi!

I'm having trouble highlighting the middle of a line using COM on word. The following code is not working as it highlights the entire line instead of just the text in between:

Code: Select all

Word_App := ComObjCreate("Word.Application")
Word_File := Word_App.Documents.Add()
Word_App.Visible := 1
Word_App.Activate


Word_App.Selection.TypeText("Unhighlighted Text`t")
Word_App.Selection.Range.HighlightColorIndex := 6
Word_App.Selection.TypeText("Highlighted Text`t")
Word_App.Selection.Range.HighlightColorIndex := 0
;Word_App.Options.DefaultHighlightColorIndex := 0
Word_App.Selection.TypeText("Unhighlighted Text 2`n")
Neither the Word_App.Selection.Range.HighlightColorIndex := 0 or the commented out Word_App.Options.DefaultHighlightColorIndex := 0 are working for me.

Thank you so much for any help you can provide!
Last edited by gregster on 01 Mar 2022, 19:31, edited 1 time in total.
Reason: Topic moved from 'Ask For Help (v2)', since it doesn't seem to be v2 code.

Return to “Ask for Help (v1)”