为什么ImportXML方法导致运行时错误9?

时间:2019-02-20 13:53:53

标签: excel vba

代码:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = [Namensfilter].Row And Target.Column = [Namensfilter].Column Then
        Dim Displayname As String: Displayname = [Namensfilter].Value + "*"
        Dim Map As XmlMap
        Set Map = ActiveWorkbook.XmlMaps(1)
        Dim urlXML As String
        urlXML = "http://direx.corproot.net/DirExWeb/Scripts/Public/GetXML.aspx?displayname=" & Displayname & ""
        ThisWorkbook.XmlMaps(Map).ImportXml urlXML
        Map.DataBinding.Refresh
    End If
End Sub

我想在另一个表中进行XML解析,但是当我导入XML文件时,出现运行时错误9。当我更改

urlXML = "http://direx.corproot.net/DirExWeb/Scripts/Public/GetXML.aspx?displayname=" & Displayname & ""
    ThisWorkbook.XmlMaps(Map).ImportXml urlXML

Map.DataBinding.LoadSettings "http://direx.corproot.net/DirExWeb/Scripts/Public/GetXML.aspx?displayname=" & Displayname & ""

Map.DataBinding.LoadSettings ("http://direx.corproot.net/DirExWeb/Scripts/Public/GetXML.aspx?displayname=" & Displayname & "")

我遇到了一个非常奇怪的错误,我也发现了here。 如何提供运行时错误9?

1 个答案:

答案 0 :(得分:0)

我需要在链接中设置*。

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row = [Namensfilter].Row And Target.Column = [Namensfilter].Column Then
        Dim Displayname As String: Displayname = [Namensfilter].Value
        Dim Map As XmlMap
        Set Map = ActiveWorkbook.XmlMaps(1)
        Dim urlXML As String
        urlXML = "http://direx.corproot.net/DirExWeb/Scripts/Public/GetXML.aspx?displayname=" & Displayname & "*"
        Map.DataBinding.LoadSettings urlXML
        Map.DataBinding.Refresh
    End If
End Sub