从网页中拉出信息并输入到单元格

时间:2017-03-13 22:22:39

标签: excel vba excel-vba

如何将这些信息显示为消息框,而不是将这些信息显示为Sheet1.Range(" A1")?非常感谢任何帮助。

Sub Demo()
With CreateObject("Msxml2.XMLHTTP")
    .Open "GET", "http://www.realtytrac.com/property" & Sheet1.Range("J11"), False
    .setRequestHeader "DNT", "1"
    .Send
    MsgBox Split(Split(.responseText, "itemprop='propertyID'>")(1), "<")(0)
End With

End Sub

2 个答案:

答案 0 :(得分:2)

Sub Demo()
With CreateObject("Msxml2.XMLHTTP")
    .Open "GET", "http://www.realtytrac.com/property" & Sheet1.Range("J11"), False
    .setRequestHeader "DNT", "1"
    .Send
    val = Split(Split(.responseText, "itemprop='propertyID'>")(1), "<")(0)
    ThisWorkbook.Sheets(1).Range("A1").value = val
End With
End Sub

答案 1 :(得分:1)

如果您的XMLHTTP对象中有有效响应,则应该能够使用以下内容:

Sub Demo()
With CreateObject("Msxml2.XMLHTTP")
    .Open "GET", "http://www.realtytrac.com/property" & Sheet1.Range("J11"), False
    .setRequestHeader "DNT", "1"
    .Send
    ThisWorkbook.Sheets(1).Range("A1").Value = Split(Split(.responseText, "itemprop='propertyID'>")(1), "<")(0)
End With
End Sub