2

您好我正在尝试使用以下代码在 excel VBA 中打开一个 URL

Public Sub downloadCode()
Dim xHttp As MSXML2.XMLHTTP
Dim hdoc As MSHTML.HTMLDocument
Dim hElem As MSHTML.HTMLGenericElement
Set xHttp = New MSXML2.XMLHTTP
URL = Sheet8.Range("U3").value

If InStr(URL, "ebay.co.uk") = 0 Then
    MsgBox ("Invalid Ebay Link. Row:" & i)
    Exit Sub
End If

xHttp.Open "GET", URL
xHttp.send

Do
    DoEvents
Loop Until xHttp.ReadyState = 4

'put into an htmldocument object
Set hdoc = New MSHTML.HTMLDocument
hdoc.body.innerHTML = xHttp.responseText
xHttp.abort
Dim MyFile1, fnum1
MyFile1 = "C:\hp\outputFromExcel1.txt"
fnum1 = FreeFile()
Open MyFile1 For Output As fnum1
Print #fnum1, hdoc.body.innerHTML
Close #fnum1
Shell "C:\WINDOWS\explorer.exe """ & MyFile1 & "", vbNormalFocus
End Sub

我要下载的网址是: http ://www.ebay.co.uk/itm/Single-Charging-Station-Dock-for-Xbox-360-Controller-White-/150723862162?pt=UK_Chargers_Docks&hash=item2317d79e92

我的浏览器是 IE9 和 Windows7,但是它在一台 PC 上返回正确的数据,但在另一台具有相同配置的 PC 上返回不同的数据,可能是什么问题?我在浏览器中打开了 URL,它们的 HTML 源代码是相同的。

4

0 回答 0