VBAXMLCode/Not运行Office 2013下and/or工作网络

VBA XML Code/Not Running under Office 2013 and/or work network

我修改了现有代码以从国家气象服务提要中解析出一些 XML 数据。它 运行 在我的家用计算机 (excel 2007) 上没有问题。它没有 运行 我的工作 pc/network 和 excel 2013.

抛出以下错误。

Run-time error '-2147012894 (80072ee2)':
Automation error

有什么见解吗?网络问题还是 2007 到 2013 的兼容性问题?我可以在我的浏览器中毫无问题地解析提要。

Option Explicit

Sub GetData()


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim ws As Worksheet
Set ws = ActiveSheet

Dim Req As New ServerXMLHTTP
Dim Resp As New DOMDocument
Dim i As Integer
Dim Wthr As IXMLDOMNode
Dim geo As IXMLDOMNode
Dim cell As Range
Dim fn As WorksheetFunction
Dim y As Integer
Dim x As Integer


Set fn = Application.WorksheetFunction

Dim Eff, Exp, et, severity As String
Dim splitstring As Variant


ws.Range("A6").CurrentRegion.Clear

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Get Weather Alerts
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Req.Open "GET", "https://alerts.weather.gov/cap/us.atom", False
Req.send
Resp.LoadXML Req.responseText

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Write alerts to worksheet
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
y = 1
For Each Wthr In Resp.getElementsByTagName("entry")
    i = i + 1


    severity = Wthr.SelectNodes("cap:severity")(0).Text
et = Wthr.SelectNodes("cap:event")(0).Text

   For Each geo In Wthr.SelectNodes("cap:geocode")
   splitstring = Split(geo.SelectNodes("value")(0).Text, " ")
   For x = LBound(splitstring) To UBound(splitstring)
   y = y + 1
   ws.Cells(y, 1).Value = splitstring(x)
   ws.Cells(y, 2).Value = severity
     ws.Cells(y, 3).Value = et
   Next x
   Next

Next Wthr

End Sub

问题似乎出在 ServerXMLHTTP 上。 ServerXMLHTTP 不会自动发现代理设置,我的公司使用代理脚本(我应该包含此信息)。

如果我使用 XMLHTTP,代码 运行s。我相信代码使用 ServerXMLHTTP 是因为缓存问题,所以我不确定我是否会 运行 进入其他问题。

修订后的代码

Option Explicit

Sub GetData()


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Variables
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim ws As Worksheet
Set ws = ActiveSheet

Dim Req As New XMLHTTP
Dim Resp As New DOMDocument
Dim i As Integer
Dim Wthr As IXMLDOMNode
Dim geo As IXMLDOMNode
Dim cell As Range
Dim fn As WorksheetFunction
Dim y As Integer
Dim x As Integer


Set fn = Application.WorksheetFunction

Dim Eff, Exp, et, severity As String
Dim splitstring As Variant


ws.Range("A6").CurrentRegion.Clear

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Get Weather Alerts
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Req.Open "GET", "https://alerts.weather.gov/cap/us.atom", False
Req.send
Resp.LoadXML Req.responseText

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Write alerts to worksheet
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
y = 1
For Each Wthr In Resp.getElementsByTagName("entry")
    i = i + 1


    severity = Wthr.SelectNodes("cap:severity")(0).Text
et = Wthr.SelectNodes("cap:event")(0).Text

   For Each geo In Wthr.SelectNodes("cap:geocode")
   splitstring = Split(geo.SelectNodes("value")(0).Text, " ")
   For x = LBound(splitstring) To UBound(splitstring)
   y = y + 1
   ws.Cells(y, 1).Value = splitstring(x)
   ws.Cells(y, 2).Value = severity
     ws.Cells(y, 3).Value = et
   Next x
   Next

Next Wthr

End Sub