Using COM to manipulate Microsoft Word's Navigation task pane

Get help with using AutoHotkey and its commands and hotkeys
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Using COM to manipulate Microsoft Word's Navigation task pane

11 Aug 2017, 18:18

Hi folks,

I am looking for a COM solution that's equivalent to using the keyboard shortcut ^f for "Find" in Microsoft Word. Basically, I am trying to find an alternative to the following simple command:
The following code opens a "Find and Replace" window:

Code: [Select all] [Download] GeSHi © Codebox Plus

oWord := ComObjActive("Word.Application")
oWord.Activate
oWord.Dialogs(112).Show ; wdDialogEditFind = 112
but what I am really after is opening the Navigation task pane. The lines below do so and bring focus to the edit control, like ^f does:

Code: [Select all] [Download] GeSHi © Codebox Plus

oWord := ComObjActive("Word.Application")
oWord.Activate
oWord.TaskPanes(18).Visible := true ; wdTaskPaneNav = 18
;~ oWord.CommandBars("Navigation").Visible := true ; this also works
ControlFocus, RICHEDIT60W1, A ; Set input focus to the edit control
Is there a COM solution to the ControlFocus command? Also, is there a COM (or non-COM) way to select the Results control that's part of the Headings/Pages/Results controls under the edit box?

Thank you.

- iPhilip

P.S.: The above code was tested under Word 2016.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: Using COM to manipulate Microsoft Word's Navigation task pane

16 Aug 2017, 11:00

Bump.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
Elgin
Posts: 103
Joined: 30 Sep 2013, 09:19

Re: Using COM to manipulate Microsoft Word's Navigation task pane

16 Aug 2017, 13:19

I don't know if there's anything in the Word Com object but at least MSAA should be able to get to those controls. Word is usually very well accessible.
See here:
https://autohotkey.com/boards/viewtopic.php?t=26201
and many posts on the forum about using it.
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: Using COM to manipulate Microsoft Word's Navigation task pane

17 Aug 2017, 11:04

Thank you, Elgin, for your recommendation. I spent some time learning about Acc.ahk from those links and came up with the following:

Code: [Select all] [Expand] [Download] (OpenWordFind.ahk)GeSHi © Codebox Plus

The best I could do was get the coordinates of the tab and click it as I didn't see an easy way to use Acc to select it. If you are aware of a simpler method, I would appreciate it if you could let me know.

Cheers!
Last edited by iPhilip on 17 Aug 2017, 11:50, edited 1 time in total.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
jeeswg
Posts: 4981
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Using COM to manipulate Microsoft Word's Navigation task pane

17 Aug 2017, 11:35

Does this work for you?

Code: [Select all] [Download] GeSHi © Codebox Plus

oAcc := Acc_Get("Object", "4.6.1." Navigation[Tab], 0, "ahk_id " ControlHwnd)
oAcc.accDoDefaultAction(0)
oAcc := ""


Haha I didn't know you could use Acc_Get like that: 'Acc_Get("Location"'.

[EDIT:] I see it has these suggested: Location,Object,Role,State,ChildCount,Selection,Focus, and possibly others will work too.
iPhilip
Posts: 288
Joined: 02 Oct 2013, 12:21

Re: Using COM to manipulate Microsoft Word's Navigation task pane

17 Aug 2017, 11:54

Yes! Thank you for the suggestion. :) Here is the updated script:

Code: [Select all] [Expand] [Download] (OpenWordFind.ahk)GeSHi © Codebox Plus

Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)

Return to “Ask For Help”

Who is online

Users browsing this forum: AlphaBravo, Gabby, RobbieWilkes and 89 guests