Selecting/actioning items in Kendo UI widgets using Excel VBA

后端 未结 3 1678
时光说笑
时光说笑 2021-01-03 17:32

Stuck - Need help !

I\'m trying to automate actioning items in an IE web page on our internal company site. I\'m able to fill out any kind of text object

3条回答
  •  误落风尘
    2021-01-03 18:00

    Here is my attempt. I tried to explain as much as possible in the comments. Let me know how it's going, based on the HTML posted, it seems like this should work, but please let us know :)

    I'm assuming you already have an IE window open and need to get a pointer to that window. Update the "myWebSiteURL" in the getIEPointer function to be the URL of the site you are trying to access. Less is more in this case as I'm doing a wildcard match. E.g. looking for 'goo' would match a url of 'Good' and 'Google'.

    Option Explicit
    
    Public Sub getElements()
        Dim ie As Object
    
        'I'm assuming you already have it open in IE, if not, then load the page
        Set ie = getIEPointer("myWebSiteURL")
    
        'Exit if the window couldn't be located
        If ie Is Nothing Then
            Debug.Print "No Window Found!"
            Exit Sub
        End If
    
        Dim element As Object
    
        'get the Div element which contains all the elements we are interested in
        'If this doesn't work, make sure your pages doesn't contain FRAMES
        'Here's a page about Frames
        'https://stackoverflow.com/questions/16699267/vba-ie-automation-read-iframe
        Set element = ie.Document.getElementById("drgdLease")
    
        'Select the first instance of the tbody element in the drgdLease div
        Set element = element.getElementsByTagName("tbody")(0)
    
        'Select the first instance of the td, inside the TBody
        Set element = element.getElementsByTagName("td")(0)
    
        'Interact with the element
        element.Click
        element.Value = "12345"
    
    End Sub
    
    'This function will return an IE object, I'm assuming the page is already open
    Private Function getIEPointer(ByRef UrlPart As String) As Object
        Dim window As Object
    
        For Each window In CreateObject("Shell.Application").Windows()
            If window.LocationURL Like "*" & UrlPart & "*" Then
                Set getIEPointer = window
                Exit Function
            End If
        Next
    
        Set getIEPointer = Nothing
    End Function
    

提交回复
热议问题