1

I want to click on the following link

enter image description here

I have the class name and the line code I was trying ot use is the following:

objIE.document.getElementByClassName("msDataText searchLink").Click

This may well be a very basic question.. any guidance

Thanks a lot

Emanuele
  • 57
  • 6

1 Answers1

1

Not sure if it is a duplicate question. A good function GetHTTPResult is already available from the link. You need to just pass the url for the GET request to fetch the data. For POST request (this function will not work), you need to make a POST request with postdata.

Also there is a sample for XMLHttpRequest at link

Function GetHTTPResult(sURL As String) As String
    Dim XMLHTTP As Variant, sResult As String

    Set XMLHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    XMLHTTP.Open "GET", sURL, False
    XMLHTTP.Send
    Debug.Print "Status: " & XMLHTTP.Status & " - " & XMLHTTP.StatusText
    sResult = XMLHTTP.ResponseText
    Debug.Print "Length of response: " & Len(sResult)
    Set XMLHTTP = Nothing
    GetHTTPResult = sResult
End Function
Community
  • 1
  • 1
Mukul Varshney
  • 3,131
  • 1
  • 12
  • 19
  • I will try this, but I thought there may have been a way without actually extracting the reference, to select (or activate) the link. In thesame way I can search by tag the search bottom of google my expectation is that I could .click the link once I pointed to it through a getelementbyclass function.. ah I am using excel 2013 to pull data out finace site (if this add info to the request) – Emanuele Mar 30 '17 at 21:07
  • Actually, after a better seach I found this link http://stackoverflow.com/questions/24638533/how-do-i-use-excel-vba-to-click-a-link-on-a-web-page. The last comment seems to point at hte solution i was proposing but seems not to work.. – Emanuele Mar 30 '17 at 21:38
  • Remove the click, make it as `Dim obj As Object` `Set obj = objIE.document.getElementByClassName("msDataText searchLink")` Assign it to an object and in watch window see the details of the object. It will give you some hint. – Mukul Varshney Mar 31 '17 at 03:26
  • out of context... I attach the full code till the point it crashes.. pleae let me know. – Emanuele Apr 01 '17 at 22:38