vba 用户定义类型未定义 windows 10

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43474704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:28:50  来源:igfitidea点击:

User-defined Type not defined windows 10

xmlexcelvbadomdocument

提问by Thomas

I have this sub that gets weather information from a weather API. It works on Windows 7 computers but not Windows 10. I get a "User-defined type not defined" error and it highlights the Dim Req As New XMLHTTPline. I have tried to change the DOMDocument to DOMDocument60 and Ive tried to make sure the MicrosoftXML V6.0 is checked.

我有这个从天气 API 获取天气信息的子程序。它适用于 Windows 7 计算机,但不适用于 Windows 10。我收到“未定义用户定义的类型”错误并突出显示该Dim Req As New XMLHTTP行。我已经尝试将 DOMDocument 更改为 DOMDocument60 并且我已经尝试确保检查了 MicrosoftXML V6.0。

Public Sub GetWeather(APIurl As String, sted As String)

    Dim i As Integer
    Dim ws As Worksheet: Set ws = ActiveSheet
    Dim city As String
    Dim omraade As String
    Dim Req As New XMLHTTP
    Dim Weather As IXMLDOMNode
    Dim wShape As Shape
    Dim thisCell As Range
    Dim Resp As New DOMDocument60

    i = 0
    omraade = ""
    omraade = sted

    Select Case omraade
        Case "Area1"
            i = 4
        Case "Area2"
            i = 6
        Case "Area3"
            i = 8
    Case Else
        Exit Sub
    End Select

    Req.Open "GET", "" & APIurl & "", False
    Req.Send
    Resp.LoadXML Req.responseText

    For Each Weather In Resp.getElementsByTagName("current_condition")

        Set thisCell = ws.Range(Cells(2, i), Cells(2, i))
        Set wShape = ws.Shapes.AddShape(msoShapeRectangle, thisCell.Left, thisCell.Top, thisCell.Width, thisCell.Height)

        wShape.Fill.UserPicture Weather.ChildNodes(4).Text 'img

        Cells(3, i).Value = "" & Weather.ChildNodes(7).Text * 0.28 & " m/s" 'windspeedkmph
        Cells(4, i).Value = Weather.ChildNodes(9).Text 'Direction
        Cells(5, i).Value = Weather.ChildNodes(1).Text & " C"  'observation time
    Next Weather

End Sub

Any ideas?

有任何想法吗?

采纳答案by Thomas

With the Microsoft XML v6.0 library properly referenced in Tools, References, the appropriate call is,

在工具、参考中正确引用 Microsoft XML v6.0 库后,适当的调用是,

Dim req As New MSXML2.XMLHTTP60

回答by Mark McClure

I changed from XML 6.0 to XML 3.0 in Tools, References and now works on both Windows 7 and Windows 10...

我在工具、参考中从 XML 6.0 更改为 XML 3.0,现在可以在 Windows 7 和 Windows 10 上运行...