3

一天的问候,

嗨,我是使用 vb 6.0 的初学者。我正在使用以下代码并获取“未定义用户定义的类型”。代码如下。我得到错误的行被突出显示。请帮助。我应该添加一些引用或组件吗?如果是的话,它会是什么。你及时和善意的帮助对我更有帮助

Public Sub LoadDocument() 
    Dim xDoc As MSXML2.DOMDocument
    Set xDoc = New MSXML2.DOMDocument 
    xDoc.async = False 
    xDoc.validateOnParse = False
    If xDoc.Load("C:\Users\284582\Desktop\XML1.xml") Then
            DisplayNode xDoc.ChildNodes, 0 
    End If 
End Sub    

' Error on this line'
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
           ByVal Indent As Integer)    

    Dim xNode As MSXML.IXMLDOMNode
    Indent = Indent + 2    
    For Each xNode In Nodes
        If xNode.NodeType = NODE_TEXT Then

            Debug.Print Space$(Indent) & xNode.ParentNode.nodeName & _
                ":" & xNode.NodeValue 
        End If    

        If xNode.HasChildNodes Then   
            DisplayNode xNode.ChildNodes, Indent  
        End If    
    Next xNode   
End sub    
4

2 回答 2

3

MSXML2.IXMLDOMNodeList,不是MSXML.IXMLDOMNodeList

于 2012-12-08T15:03:46.550 回答
1

您的参考文献中可能缺少该库。尝试这个。

手动添加 MSXML2

1. Open MS Access.
2. Database Tools ribbon
3. Visual Basic  ribbon item (icon)
4. Double-click on any module to open it.

5. Tools menu
6. References…
7. Find  Microsoft XML, v6.0. is in the list
    a. If in list but not checked, check it and click [OK].
    b. If not in the list: 
        i. click [Browse…] and add "c:\windows\system32\msxml6.dll"
8. [OK] your way back to the Visual Basic window.
9. Close the Visual Basic Window.  You should be good to go.

以编程方式添加 MSXML2 添加以下子和函数。运行子。如有必要,编辑 sub 以包含路径。

检查库中损坏的引用改编自以编程方式添加引用

Sub CheckXmlLibrary()
' This refers to your VBA project.
    Dim chkRef As Reference, RetVal As Integer  ' A reference.
    Dim foundWord As Boolean, foundExcel As Boolean, foundXml As Boolean
    foundWord = False
foundExcel = False
    foundXml = False

' Check through the selected references in the References dialog box.
    For Each chkRef In References
' If the reference is broken, send the name to the Immediate Window.
        If chkRef.IsBroken Then
           Debug.Print chkRef.Name
        End If
'copy and repeat the next 2 if statements as needed for additional libraries.
    If InStr(UCase(chkRef.FullPath), UCase("msxml6.dll")) <> 0 Then
                foundXml = True
            End If
    Next

    If (foundXml = False) Then
            'References.AddFromFile ("C:\Windows\System32\msxml6.dll")  <-- For other than XML, modify this line and comment out line below.
            RetVal = AddMsXmlLibrary
            If RetVal = 0 Then MsgBox "Failed to load XML Library (msxml6.dll).  XML upload/download will not work."
    End If

End Sub

将 XML 引用添加到由 Chris Advena 开发的库。感谢http://allenbrowne.com/ser-38.html的洞察力。

Public Function AddMsXmlLibrary(Optional PathFileExtStr As String = "C:\Windows\System32\msxml6.dll") As Integer
On Error GoTo FoundError
AddMsXmlLibrary = 1
References.AddFromFile (PathFileExtStr)

AllDone:
    Exit Function
FoundError:
    On Error Resume Next
    AddMsXmlLibrary = 0
    On Error GoTo 0
End Function
于 2014-04-30T21:54:11.373 回答