2012-12-08 102 views
2

當天的問候,錯誤代碼中的'用戶定義類型未定義'

嗨,我是一個初學者使用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  
+0

VB6和VB.NET在系統基礎設施方面是兩回事。你在這裏使用哪一個? – Steve

+0

您好史蒂夫,我使用Visual Basic 6.0 – user1724956

回答

2

MSXML2.IXMLDOMNodeList,不MSXML.IXMLDOMNodeList

+2

他也許應該添加'Option Explicit'或更好的,但打開IDE選項以使它在創建模塊時自動生成。 – Bob77

0

您的參考文獻可能缺失該庫。嘗試這個。

手動添加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 添加以下子和功能。運行子。如有必要,編輯子包含路徑。

Add references programatically

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參考克里斯開發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 
相關問題