Gener4tor
Gener4tor

Reputation: 388

Is it possible to use the temporary object of a with-statement as a parameter for a function?

I use a with statement in VBA like this:

With New MSXML2.DOMDocument60
    'Some statements
end with

and I have got a sub like this:

Private Sub anyfunction(ByVal par_document As MSXML2.DOMDocument60)

end sub

Is there a way to use the the temporary object as the parameter for the anyfunction or do I have to create a variable with "Dim" in order to use the anyfunction?

Upvotes: 2

Views: 95

Answers (1)

ComputerVersteher
ComputerVersteher

Reputation: 2686

If the object provides a reference to it self, use that. ForMSXML2.DOMDocument60you can use.SelectSingleNode("/")or use a child-object with a reference to the parent-object. (e.g..documentElement.ownerDocumentor.childNodes(0).parentNode, but they need a XML-Document loaded.) Or the opposite (parent to child) forDao.Recordsetuse.Parent.RecordSets(.Name).

With New MSXML2.DOMDocument60
    .Load("xmlfile")
    anyfunction(.SelectSingleNode("/"))
end with

Upvotes: 0

Related Questions