他们的意义是否一样啊?

解决方案 »

  1.   

    有区别,主要是
    1、CreateObject 在运行时绑定变量,而AS是在编译时
    2、CreateObject 可以创建远程COM对象看看下面的解释:
    --------------------------------------------------------
     
    CreateObject Function
          Creates and returns a reference to an ActiveX object.SyntaxCreateObject(class,[servername])The CreateObject function syntax has these parts:Part Description 
    class Required; Variant (String). The application name and class of the object to create. 
    servername Optional; Variant (String). The name of the network server where the object will be created. If servername is an empty string (""), the local machine is used. The class argument uses the syntax appname.objecttype and has these parts:Part Description 
    appname Required; Variant (String). The name of the application providing the object. 
    objecttype Required; Variant (String). The type or class of object to create. ResEvery application that supports Automation provides at least one type of object. For example, a word processing application may provide an Application object, a Document object, and a Toolbar object.To create an ActiveX object, assign the object returned by CreateObject to an object variable:' Declare an object variable to hold the object 
    ' reference. Dim as Object causes late binding. 
    Dim ExcelSheet As Object
    Set ExcelSheet = CreateObject("Excel.Sheet")This code starts the application creating the object, in this case, a Microsoft Excel spreadsheet. Once an object is created, you reference it in code using the object variable you defined. In the following example, you access properties and methods of the new object using the object variable, ExcelSheet, and other Microsoft Excel objects, including the Application object and the Cells collection.' Make Excel visible through the Application object.
    ExcelSheet.Application.Visible = True
    ' Place some text in the first cell of the sheet.
    ExcelSheet.Application.Cells(1, 1).Value = "This is column A, row 1"
    ' Save the sheet to C:\test.xls directory.
    ExcelSheet.SaveAs "C:\TEST.XLS"
    ' Close Excel with the Quit method on the Application object.
    ExcelSheet.Application.Quit
    ' Release the object variable.
    Set ExcelSheet = NothingDeclaring an object variable with the As Object clause creates a variable that can contain a reference to any type of object. However, access to the object through that variable is late bound; that is, the binding occurs when your program is run. To create an object variable that results in early binding, that is, binding when the program is compiled, declare the object variable with a specific class ID. For example, you can declare and create the following Microsoft Excel references:Dim xlApp As Excel.Application 
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.WorkSheet
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)The reference through an early-bound variable can give better performance, but can only contain a reference to the class specified in the declaration.You can pass an object returned by the CreateObject function to a function expecting an object as an argument. For example, the following code creates and passes a reference to a Excel.Application object:Call MySub (CreateObject("Excel.Application"))You can create an object on a remote networked computer by passing the name of the computer to the servername argument of CreateObject. That name is the same as the Machine Name portion of a share name: for a share named "\\MyServer\Public," servername is "MyServer."Note   Refer to COM documentation (see Microsoft Developer Network) for additional information on making an application visible on a remote networked computer. You may have to add a registry key for your application.The following code returns the version number of an instance of Excel running on a remote computer named MyServer:Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application", "MyServer")
    Debug.Print xlApp.VersionIf the remote server doesn’t exist or is unavailable, a run-time error occurs.Note   Use CreateObject when there is no current instance of the object. If an instance of the object is already running, a new instance is started, and an object of the specified type is created. To use the current instance, or to start the application and have it load a file, use the GetObject function.If an object has registered itself as a single-instance object, only one instance of the object is created, no matter how many times CreateObject is executed.
      

  2.   

    不好意思,有点长了。Copy的帮助文件里面的。:)
      

  3.   

    1 . createobject与new   本质的不同。   
      createobject与new   的关键区别就是声明后系统对资源的控制权不一样。   
      createobject是由内存中重新创建一个实例而不是简单的资源计数器+1的概念。如果内存中存在一个这样的实例,编译器不会理会这个实例而是将对象重新创建一个。实际上是一个完全独立的新的资源实例。并且不受GC的资源回收控制,必须自己回收。   
      new声明的时候,编译器回自动寻找内存中的相应实例,找到了以后,将资源计数器+1,并不会在内存中重新声明内存地址空间,他是受GC限制的,当编译器运行完毕后,会自动将资源编译器里面的该对象的资源计数器-1,如果为计数器0的话就自动释放该对象。   
    2.New的时候,调用的是那个带下划线的接口   
      CreateObject的时候,返回IDispatch接口   
      带下划线的接口是VB一种特殊方法,自VB4,Office97以后就这么   
      用了,以前的好象只能用IDispatch接口.3.还有就是要说的是那个前期绑定和后期   
      New是前   
      CreateObject是后期   
      因为New的时候必须加入类型库   
      有类型检查   
      而后者没有,所有的调用都可能成功,自已检查
    这是网上找的,仅仅相对你编码创建对象来说,没有什么区别另外几点new出来的可以.出属性和方法出来,createObjec的没有,这也就是上面3说的
    createObject的对象,回收时要写set obj = nothing显示回收,这就是上面1说的