使用Excel的UI自动化 [英] UI automation with excel

查看:379
本文介绍了使用Excel的UI自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UI自动化的新手.在我目前的组织中,我的任务是使用GUI(图形用户界面)屏幕阅读制作自动化工具,但是由于屏幕分辨率不同,它无法与其他同事的机器完美配合.

I am new to UI Automation. In my current organisation I was tasked with making an automated tool using GUI(Graphics User Interface) screen reading, but it is not working perfectly with other my colleague's machine because of a difference in screen resolution.

我在您的网上观看了链接以尝试并了解使用excel进行的UI自动化,但是在其他任何地方都找不到关于此主题的很多信息.

I watched this link on you-tube to try and understand UI Automation with excel, but I can't find much on this topic anywhere else.

任何人都可以将我引向UI自动化方面的资源吗?我想知道我在哪里可以学习,了解它以及如何使用Excel来实现它.

Can anyone direct me toward resources on UI Automation? I Would like to know where I can learn it, read about it, and how to implement it with Excel.

在此先感谢您能帮助我.

Thanks in advance I really appreciate if anyone could help me.

推荐答案

Microsoft的UIAutomation功能非常强大,并且可以与Visual Basic的Windows 7、8、10(适用于32位和64位)一起很好地使用,并且可以方便地使用不用昂贵的工具就能完成一些不错的GUI自动化.

UIAutomation from Microsoft is very powerfull and works well with windows 7, 8, 10 also from visual basic for applications (32 and 64 bits) and can be handy used to do some nice GUI Automation without expensive tools.

确保在VBA引用中具有UIAutomationCore.Dll引用(有时在某些计算机上需要将其复制到文档文件夹中,这很奇怪)

Make sure in VBA reference you have UIAutomationCore.Dll references (and weird enough sometimes on some computers you have to copy this to your documents folder)

在下面您可以看到2个基本示例,但是由于MS Automation是所有例程的庞大库,因此您可以在MSDN上阅读很多有关完整文档的内容. 我在AutoIt和VBA中使用MS UIA例程

Below you can see 2 base examples but as MS Automation is a huge library for all routines you can read a lot on MSDN for full documentation. I use the MS UIA routines in AutoIt and in VBA

  • 对于AutoIt,它在此处共享

https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/

  • For VBA I do not have a standard library but someone did a try with this https://github.com/mhumpher/UIAutomation_VBA

显式选项

Sub test()
    Dim c As New CUIAutomation
    Dim oDesktop As IUIAutomationElement

    Set oDesktop = c.GetRootElement

    Debug.Print oDesktop.CurrentClassName & vbTab & oDesktop.CurrentName & vbTab & oDesktop.CurrentControlType

End Sub

'Test uia just dumps all windows of the desktop to the debug window
Sub testUIA()
    Dim allEl As IUIAutomationElementArray                  'Returns an element array with all found results
    Dim oElement As IUIAutomationElement                    'Reference to an element
    Dim ocondition As IUIAutomationCondition

    Dim i As Long
    Dim x As New clsUIA


    'Just reference the three mainly used properties. many more are available when needed
    Debug.Print x.oDesktop.CurrentName & x.oDesktop.CurrentClassName & x.oDesktop.CurrentControlType

    Set ocondition = x.oCUIAutomation.CreateTrueCondition             'Filter on true which means get them all
    Set allEl = x.oDesktop.FindAll(TreeScope_Children, ocondition)    'Find them in the direct children, unfortunately hierarchies are strange sometimes

    'Just reference the three mainly used properties. many more are available when needed
    For i = 0 To allEl.Length - 1
        Set oElement = allEl.GetElement(i)
        ' If oElement.CurrentClassName = "PuTTY" Then
          Debug.Print oElement.CurrentClassName & oElement.CurrentName & oElement.CurrentControlType
           ' Debug.Print oElement.CurrentBoundingRectangle

            oElement.SetFocus
            DoEvents
            Sleep 2000
       ' End If

    Next
End Sub    

这篇关于使用Excel的UI自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆