Consulting

Results 1 to 2 of 2

Thread: Button Click in Internet - Button without 'Name'!!

  1. #1
    VBAX Regular
    Joined
    Dec 2010
    Posts
    12
    Location

    Button Click in Internet - Button without 'Name'!!

    Hi all,

    I am having problem clicking a button in an Internet Browser where the source code for the button only gives the (1) input type & (2) id BUT not the (3) name!

    SOURCE CODE FOR BUTTON WITHOUT NAME
    <input type="button" id="ImportingButton" class="C00_Button1" value="Importingvalue" onclick="performUpload();"/>

    I have already successfully written a code to click internet buttons WITH names:

    SOURCE CODE FOR BUTTON WITH NAME
    <input type="button" name="ImportingButton" id="ImportingButton" class="C00_Button1" value="Importingvalue" onclick="performUpload();"/>
    VBA CODE TO CLICK BUTTON
    Sub ClickButton()
    Dim objIE as InternetExplorer, appIE as InternetExplorer
    Dim btnInput as MSHTML.HTMLInputElement
    Dim ElementCol As MSHTML.IHTMLElementCollection
    Dim Done as Long, Nm as Long
    Dim url as string
    Application.ScreenUpdating = False
    Nm = 1234
    Set appIE = New InternetExplorer
    url = (the website link I'm trying to access)
    ' ---- click the editbutton (start) ----
    Set ElementCol = appIE.document.getElementsByTagName("Input")
    For Each btInput In ElementCol
        If btInput.name = "ImportingButton" Then
            Done = Done + 1
            btnInput.Click
        End If
    Next btnInput
    ' --- click the editbutton (end) ---
    End Sub
    ** MODIFIED VBA CODE TO CLICK BUTTON **
    Sub ClickButton()
    Dim objIE as InternetExplorer, appIE as InternetExplorer
    Dim btnInput as MSHTML.HTMLInputElement
    Dim ElementCol As MSHTML.IHTMLElementCollection
    Dim Done as Long, Nm as Long
    Dim url as string
    Application.ScreenUpdating = False
    Nm = 1234
    Set appIE = New InternetExplorer
    url = (the website link I'm trying to access)
    ' ---- click the editbutton (start) ----
    Set ElementCol = appIE.document.getElementsByTagName("Input")
    For Each btInput In ElementCol
        If btInput.ID = "ImportingButton" Then
            Done = Done + 1
            btnInput.Click
        End If
    Next btnInput
    ' --- click the editbutton (end) ---
    End Sub
    When I ran the above macro, the program hung & I had to force-stop the macro by pressing 'Ctrl-Break'
    When I investigated the debugging portion --> it highlighted the code 'btnInput.ID...'

    Believe this can be solved BUT no clue now..Hope someone can advise!!
    Thanks everyone!!!
    Last edited by Aussiebear; 04-19-2023 at 01:28 AM. Reason: Adjusted the code tags

  2. #2
    "button only gives the (1) input type & (2) id".

    Use getElementById then.

Posting Permissions

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