什么是使用在Excel VBA的新的关键字和调用的CreateObject之间的区别是什么? [英] What are the differences between using the New keyword and calling CreateObject in Excel VBA?

查看:734
本文介绍了什么是使用在Excel VBA的新的关键字和调用的CreateObject之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该用什么样的标准来决定是否我编写VBA code是这样的:

What criteria should I use to decide whether I write VBA code like this:

Set xmlDocument = New MSXML2.DOMDocument

或者是这样的:

Set xmlDocument = CreateObject("MSXML2.DOMDocument")

推荐答案

只要变量的类型不能为对象

As long as the variable is not typed as object

Dim xmlDocument as MSXML2.DOMDocument
Set xmlDocument = CreateObject("MSXML2.DOMDocument")

是相同的

Dim xmlDocument as MSXML2.DOMDocument
Set xmlDocument = New MSXML2.DOMDocument

都使用早期绑定。而

both use early binding. Whereas

Dim xmlDocument as Object
Set xmlDocument = CreateObject("MSXML2.DOMDocument")

使用后期绑定。请参阅MSDN href=\"http://support.microsoft.com/kb/245115\">。

uses late binding. See MSDN here.

当您创建外部提供的对象,也有新的运营商之间没有差异,声明一个变量如新,并且使用CreateObject函数。

When you’re creating externally provided objects, there are no differences between the New operator, declaring a variable As New, and using the CreateObject function.

新要求,类型库引用。而使用的CreateObject注册表。

New requires that a type library is referenced. Whereas CreateObject uses the registry.

的CreateObject可用于在远程机器上创建一个对象

CreateObject can be used to create an object on a remote machine.

这篇关于什么是使用在Excel VBA的新的关键字和调用的CreateObject之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆