Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

COM -> MS Word -> Highlight Selection


  • Please log in to reply
4 replies to this topic
Marker
  • Guests
  • Last active:
  • Joined: --
This is my MS Word macro in VB:
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow

How to translate this in AHK? I tried something like this, but it doesn't work...
wdYellow := 7	; http://msdn.microsoft.com/en-us/library/bb237561.aspx

COM_Init()
Word:=COM_GetActiveObject("Word.Application")
HighlightColor := COM_Invoke(Word,"Options.DefaultHighlightColorIndex",wdYellow)
COM_Invoke(Word,"Selection.Range.HighlightColorIndex",HighlightColor)
COM_Release(Word)
COM_Term()
Thanks in advance.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Nice try :wink: - minor detail:

wdYellow := 7   ; http://msdn.microsoft.com/en-us/library/bb237561.aspx 

COM_Init() 
Word:=COM_GetActiveObject("Word.Application") 
COM_Invoke(Word,"Options.DefaultHighlightColorIndex[color=red]=[/color]",wdYellow) 
COM_Invoke(Word,"Selection.Range.HighlightColorIndex[color=red]=[/color]",[color=red]wdYellow[/color]) 
COM_Release(Word) 
COM_Term()


Marker - [Solved]
  • Guests
  • Last active:
  • Joined: --
Thank you! :D

[Solved]


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Alternatively:

COM_Init(), Word :=	COM_GetActiveObject("Word.Application") 
COM_Invoke(Word,"Selection.Range.[color=red]Shading.BackgroundPatternColorIndex[/color]",wdYellow) 
COM_Release(Word), COM_Term()


Marker [Solved]
  • Guests
  • Last active:
  • Joined: --
sinkfaze - nice alternative

jethrow - COM_Invoke(Word,"Options.DefaultHighlightColorIndex=",wdYellow) this line is not necessary. Code below works
wdYellow := 7   ; http://msdn.microsoft.com/en-us/library/bb237561.aspx
COM_Init()
Word:=COM_GetActiveObject("Word.Application")
COM_Invoke(Word,"Selection.Range.HighlightColorIndex=",wdYellow)
COM_Release(Word)
COM_Term()