是否可以将 with 语句的临时对象用作函数的参数?
Is it possible to use the temporary object of a with-statement as a parameter for a function?
我在 VBA 中使用 with 语句是这样的:
With New MSXML2.DOMDocument60
'Some statements
end with
我有一个这样的潜艇:
Private Sub anyfunction(ByVal par_document As MSXML2.DOMDocument60)
end sub
有没有办法使用临时对象作为 anyfunction 的参数,或者我是否必须使用 "Dim" 创建一个变量才能使用 anyfunction?
如果 object 提供了对其自身的引用,请使用它。对于MSXML2.DOMDocument60
,您可以使用.SelectSingleNode("/")
或使用 child-object 并引用 parent-object。 (例如 .documentElement.ownerDocument
或 .childNodes(0).parentNode
,但它们需要加载 XML-Document。)
或者相反(parent 到 child)Dao.Recordset
use.Parent.RecordSets(.Name)
.
With New MSXML2.DOMDocument60
.Load("xmlfile")
anyfunction(.SelectSingleNode("/"))
end with
我在 VBA 中使用 with 语句是这样的:
With New MSXML2.DOMDocument60
'Some statements
end with
我有一个这样的潜艇:
Private Sub anyfunction(ByVal par_document As MSXML2.DOMDocument60)
end sub
有没有办法使用临时对象作为 anyfunction 的参数,或者我是否必须使用 "Dim" 创建一个变量才能使用 anyfunction?
如果 object 提供了对其自身的引用,请使用它。对于MSXML2.DOMDocument60
,您可以使用.SelectSingleNode("/")
或使用 child-object 并引用 parent-object。 (例如 .documentElement.ownerDocument
或 .childNodes(0).parentNode
,但它们需要加载 XML-Document。)
或者相反(parent 到 child)Dao.Recordset
use.Parent.RecordSets(.Name)
.
With New MSXML2.DOMDocument60
.Load("xmlfile")
anyfunction(.SelectSingleNode("/"))
end with