Consulting

Results 1 to 2 of 2

Thread: Cant get the macro to click a button

  1. #1

    Cant get the macro to click a button

    i have made a macro to get into a site input a criteria in the search box but cant get it to click the search button.plz advise

    CA Pulkit lila
    Attached Files Attached Files

  2. #2
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    It was a bit trickier than I first thought but another forum (link below) helped. You code with the required changes is below. You need to set a reference to the Microsoft HTML Object Library.

    [vba]Private Sub CommandButton1_Click()
    Dim htmlInput As MSHTML.HTMLInputElement
    Dim htmlColl As MSHTML.IHTMLElementCollection

    If Range("a1").Value = 1 Then

    Const BetJBN As String = "http://tracking.mscgva.ch/msctracking.php"

    UserName = Range("b5").Value
    Password = Range("b6").Value

    On Error GoTo Err_Login

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True

    With ie
    .navigate BetJBN 'address of log in page
    Do While .busy: DoEvents: Loop
    Do While .READYSTATE <> 4: DoEvents: Loop


    'this information is specific to the web page
    With .document.forms(0)
    .InputBox.Value = "trlu1234567"
    Set htmlColl = .getElementsByTagName("input")
    Do While .READYSTATE <> "complete": DoEvents: Loop
    For Each htmlInput In htmlColl
    If Trim(htmlInput.Type) = "submit" Then
    htmlInput.Click
    Exit For
    End If
    Next htmlInput


    End With
    End With

    Exit_Login:
    Exit Sub
    Err_Login:
    MsgBox Err.Number & " " & Err.Description, vbOKOnly + vbCritical, "Error"
    Resume Exit_Login

    End If

    End Sub[/vba]

    source: http://www.ozgrid.com/forum/showthread.php?t=138829
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

Posting Permissions

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