Search code examples
ms-officeautohotkeyribbononenote

How to detect what Ribbon is currently active in a Microsoft Office application?


I have looked at ActiveControlList but unfortunately it wasn't a reliable way to tell the active ribbon. Specifically, I am looking for a reliable way to tell if Equation Tools ribbon is active in OneNote. Do you have any suggestions ?


Solution

  • The ribbon is not a normal control and can be hard to work with from plain VBA or ahks built-in COM but you can use Microsoft's Active Accessibility API

    You Can use the Acc lib so you don't need to know all the dll calls

    But you still need to know what parts you need, and also what to look for to really use it. You can use jethrows AccViewer it will tell you the elements Role, State, ChildCount and more, so when you have found the item you're after, you can use the Tree or path that the accViewer gives.

    Word ribbon path Example: 4.3.4.1.4.1.4.1.4.1.4.13.1.1

    OneNote: 4.3.4.1.4.1.4.1.4.1.4.10.1.1

    Here is an example using Acc_get() to show the current ribbon Name in OneNote PP 2010 when you press F6

    f6::
    name := Acc_Get("Name", "4.3.4.1.4.1.4.1.4.1.4.10.1.1", 0, "Ahk_class Framework::CFrame")
    tooltip % name
    return
    

    Note: that this path is for when the ribbon is pinned i.e always visible

    Forum topic with images