The following code works fine on a PC-based computer. Can someone help me tweak it so it will work on a MacBook running Excel?
Sub XMLHTTP()
Dim url As String, lastRow As Long
Dim XMLHTTP As Object, html As Object, objResultDiv As Object, objH3 As Object, link As Object
Dim start_time As Date
Dim end_time As Date
lastRow = Range("A" & Rows.Count).End(xlUp).Row
Dim cookie As String
Dim result_cookie As String
start_time = Time
Debug.Print "start_time:" & start_time
Dim Test As Object
For i = 2 To lastRow
'url = "https://scholar.google.com/scholar?hl=en&q=" & Cells(i, 1) & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
url = "http://www.ncbi.nlm.nih.gov/pubmed/?term=" & Cells(i, 1) ' & "&rnd=" & WorksheetFunction.RandBetween(1, 10000)
Set XMLHTTP = CreateObject("MSXML2.serverXMLHTTP")
XMLHTTP.Open "GET", Trim(url), False
'XMLHTTP.setRequestHeader "Content-Type", "text/xml"
XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
XMLHTTP.send
Set html = CreateObject("htmlfile")
html.body.innerHTML = XMLHTTP.ResponseText
' Cells(i, 3) = html.body.innerHTML
Set objResultDiv = html.getelementbyid("see_pmcommons")
If objResultDiv Is Nothing Then
GoTo NextLoop
Else
Cells(i, 2) = "= Hyperlink(""" & url & """)"
' Cells(i, 2) = url
End If
' Set objH3 = objResultDiv.getelementsbytagname("H3")(0)
' If objH3 Is Nothing Then
' GoTo NextLoop
' Else
' Set link = objH3.getelementsbytagname("a")(0)
' End If
' If link Is Nothing Then
' Else
' Cells(i, 2) = link.href
' End If
NextLoop:
DoEvents
Next
end_time = Time
MsgBox "Done"
End Sub
Bookmarks