How to get handle of menu in external application, and find button where no text is part of class.

Galaxea

New Member
Joined
Jul 20, 2018
Messages
34
Office Version
  1. 2021
Platform
  1. Windows
@Jaafar Tribak - I have seen that you have extensive experience in this topic so I am hoping that you can help me please.

I have an external application that I can launch and control from Excel, but only up to a point.
As soon as I click on the SEND TO button and the menu pops up I can't go any further as I cannot get the handle or any other info.
Even bringing up the SPY++ tool will make the menu disappear as soon as the focus is changed off the menu.

Please contact me, even off the forum if necessary as I really need to get this working! I can't see a way to contact someone directly on this forum.

1658424498840.png


I have another similar issue with the latest version of the same program (I am in the process of upgrading to it) where I can't find enough info to know what to click to open a company file (see below).
Thanks. Rob.

1658425416226.png
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Microsoft Inspect Tool is better than Spy++ for analysing UI controls and elements.

See this page for installing Inspect:


You could control the external application from Excel with UIAutomation. Example code in these threads:

 
Upvote 0
Solution
Hi Rob,

I second John's siggestion to explore Inspect.exe... SPY++ will only detect UI elements that have a hwnd whereas Inspect.exe can detect (and act upon to a certain extent) some windowless user interface elements such as menus. This is done via the IAccessibility and IUIAutomation interfaces as long as the server application implements those interfaces.

It is also worth noting that sometimes it is difficult to access some UI elements which are only created after a user action ha been performed ( like the 3 submenus that appear in the dropdown after clicking the SendTo menu shown on your first image shot). In such cases, the client code will need to setup a windows or accessibility hook or a windows timer beforehand in order to detect the creation of the submenus.
 
Upvote 0
Thank you both for the suggestions. I am not familiar with UIAutomation so it will take some time and reading for me to see if I understand it.
If you have any examples that might be simple and relevant to the issue I am trying to resolve, please post them to help me speed up the process.

If I posted some pics of what INSPECT is showing me for those windows would it help you to tell whether it could solve my problem?
 
Upvote 0
This is what I am seeing. I don't have a clue how to now navigate to this UI element and click it.
It looks like the INSPECT tool has been replaced by this new version. Does this screen give you enough info to guide me on what to do next?
It looks like it can get the focus which is good, but how do I click on it with UIAutomation please?

1658664693239.png
 
Upvote 0
This is what I am seeing. I don't have a clue how to now navigate to this UI element and click it.
It looks like the INSPECT tool has been replaced by this new version. Does this screen give you enough info to guide me on what to do next?
It looks like it can get the focus which is good, but how do I click on it with UIAutomation please?
Inspect has been replaced by Accessibility Insights, however I prefer Inspect and find it easier to use.

It will be difficult for me to help you to automate your application using UIAutomation because I don't have the app, so I can only suggest starting with the Calculator code as an example.

Start by finding the main app window:
VBA Code:
    'Find Calculator window on Desktop
    
    Set Desktop = UIAuto.GetRootElement
    Set CalcWindow = Desktop.FindFirst(TreeScope_Children, _
                                       UIAuto.CreateAndCondition(UIAuto.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_WindowControlTypeId), UIAuto.CreatePropertyCondition(UIA_NamePropertyId, "Calculator")))
that gives you a handle to the app's window, which you use to get the app's automation element:
VBA Code:
    'Get the Calculator automation element from its window handle
    
    Set UIAuto = New CUIAutomation
    Set Calc = UIAuto.ElementFromHandle(ByVal CalcHwnd)
From there, to find a specific element use a combination of CreatePropertyCondition, CreateAndCondtion and FindFirst with TreeScope_Descendants or TreeScope_Children. Typically, you use CreateAndCondition to find an element by its ControlType and Name - see Calculator code.

To click an element, use its InvokePattern - see Calculator code.
 
Upvote 0
Inspect has been replaced by Accessibility Insights, however I prefer Inspect and find it easier to use.

It will be difficult for me to help you to automate your application using UIAutomation because I don't have the app, so I can only suggest starting with the Calculator code as an example.

To click an element, use its InvokePattern - see Calculator code.

Thanks John. I have the Calculator code working so I will go through that and your suggestions above and see how far I can get.
 
Upvote 0
I have downloaded the Inspect tool (old one) as suggested.
I am trying to get to the "Send To" - "Disk" option (see OP above).

I can see that the popup menu is not a child of the "Send To" button, but rather a top level window (green arrow).
Do you still think it is possible to find this element using UIAutomation (or standard APIs)?
Is there anything in the right-hand window below that I can use to get to it?
Please suggest how to go about it. Thanks!

1658685589427.png
 
Upvote 0
This is what I can see with the Inspect tool for the newer version of the app:

1658686925850.png


1658687158558.png
 
Upvote 0
I can see that the popup menu is not a child of the "Send To" button, but rather a top level window (green arrow).
Do you still think it is possible to find this element using UIAutomation (or standard APIs)?
Is there anything in the right-hand window below that I can use to get to it?
Please suggest how to go about it. Thanks!
Search for "Context menu" in the IE11 automation code - it has the same situation as your popup menu, whereby it is a child of the Desktop rather than a child of the IE window as one might expect.

The answer is to search the Desktop root element, something like this for your case to get the 3rd menu item (I haven't shown the lines which define/get UIAutomation and DesktopRoot):

VBA Code:
    Dim UIAutomation As IUIAutomation
    Dim NameAndType As IUIAutomationCondition
    Dim ControlType As IUIAutomationCondition
    Dim ContextMenu As IUIAutomationElement
    Dim MenuItem3 As IUIAutomationElement
     
    With UIAutomation
        Set NameAndType = .CreateAndCondition(.CreatePropertyCondition(UIA_NamePropertyId, "Context"), _
                                              .CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_MenuControlTypeId))
    End With

    Set ContextMenu = DesktopRoot.FindFirst(TreeScope_Children, NameAndType)
    
    Set ControlType = UIAutomation.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_MenuItemControlTypeId)
    Set MenuItems = ContextMenu.FindAll(TreeScope_Children, ControlType)
   
    Set MenuItem3 = MenuItems.GetElement(3)  'the 3rd menu item
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top