Results 1 to 10 of 10

Thread: Unable to Get ElementID In VBA IE Automation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    I suggest you put a break during code execution, and manually select the control, and then try to figure the ID of the activeElement

    Code:
        Dim ie As InternetExplorer    Dim obj As HTMLObjectElement
        Dim doc As HTMLDocument
        
        Set ie = New InternetExplorer
        ie.navigate "http://www.excelfox.com/forum/f2/unable-get-elementid-vba-ie-automation-851/"
        ie.Visible = True
        Do While ie.Busy: Loop
        Do While ie.readyState <> READYSTATE_COMPLETE: Loop
        Stop ' Now tab-activate the control, and come to this code again and push F8
        Set doc = ie.document
        MsgBox doc.activeElement.ID
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  2. #2
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    Mr fox i got the code running for taking element id from frame and tabels but when clicking the button throught element id code runs but does not click on the button on ie below is the code which i used

    please reply quick as need to work more on the project.

    Thanks in advance.

    Code:
    Dim myHTMLDoc As HTMLDocument
        Set myHTMLDoc = ie.document
     
        'set myHTMLFrame2 as the 2nd frame of the main page (index starts at 0)
        Dim myHTMLFrame2 As HTMLDocument
        Set myHTMLFrame2 = myHTMLDoc.frames(0).document
     
        'set myHTMLFrame2_3 as the 3rd frame of myHTMLFrame2
        Dim myHTMLFrame2_3 As HTMLDocument
        Set myHTMLFrame2_3 = myHTMLFrame2.frames(1).document
     
        'get all the tables in myHTMLFrame2_3
        Dim allTables As Object
        Set allTables = myHTMLFrame2.getElementsByTagName("Table")
     
        'set myTable as the 3rd table in allTables
        Dim myTable As HTMLTable
        Set myTable = allTables(2)
     
         For Row = 1 To myTable.Rows.Length
            For Col = 1 To myTable.Rows(Row - 1).Cells.Length
              If myTable.Rows(Row - 1).Cells(Col - 1).innerText = "Data Extraction" Then
                ash = myTable.Rows(Row - 1).Cells(Col - 1).ID
    ''''''''''''''code for clicking button
                myHTMLFrame2 .getelementbyid(ash).click    <-------doesnt work any other suggestions.
              End If
            Next Col
        Next Row

Similar Threads

  1. Replies: 17
    Last Post: 07-15-2013, 09:56 PM
  2. Replies: 1
    Last Post: 05-22-2013, 01:50 PM
  3. VBA IE Internet Explorer Automation Through ElementID
    By mrmmickle1 in forum Excel Help
    Replies: 3
    Last Post: 01-22-2013, 06:20 AM
  4. Replies: 7
    Last Post: 06-09-2012, 06:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •