Re: Object variable or With block variable not set
- From: hon123456 <peterhon321@xxxxxxxxxxxx>
- Date: Tue, 3 Jun 2008 20:32:11 -0700 (PDT)
On 6月4日, 上午11時30分, hon123456 <peterhon...@xxxxxxxxxxxx> wrote:
Dear all,
I have the following code:
Private Function MakeDoc(nl As IXMLDOMNodeList, elemName As String) As
DOMDocument40
Dim doc As New MSXML2.DOMDocument
doc.LoadXml "<" & elemName & ">"
Dim n As IXMLDOMNode
For Each n In nl
Select Case n.nodeType
Case NODE_ATTRIBUTE
doc.documentElement.setAttribute n.nodeName,
n.nodeValue
Case NODE_ELEMENT, NODE_TEXT
doc.documentElement.appendChild n
End Select
Next
Set MakeDoc = doc
End Function
When it run this line
doc.documentElement.appendChild n
VB complains Object variable or With block variable not set
What's wrong with my code . Thanks.
Sorry The Code should be
Private Function MakeDoc(nl As IXMLDOMNodeList, elemName As String) As
DOMDocument40
Dim doc As New MSXML2.DOMDocument40
doc.LoadXml "<" & elemName & ">"
Dim n As IXMLDOMNode
For Each n In nl
Select Case n.nodeType
Case NODE_ATTRIBUTE
doc.documentElement.setAttribute n.nodeName,
n.nodeValue
Case NODE_ELEMENT, NODE_TEXT
doc.documentElement.appendChild n
End Select
Next
Set MakeDoc = doc
End Function
.
- References:
- Object variable or With block variable not set
- From: hon123456
- Object variable or With block variable not set
- Prev by Date: Object variable or With block variable not set
- Next by Date: Re: Object variable or With block variable not set
- Previous by thread: Object variable or With block variable not set
- Next by thread: Re: Object variable or With block variable not set
- Index(es):
Relevant Pages
|