COMCreateObject()
syntax: |
COMCreateObject(COMObject) |
where: |
COMObject - the name of a COM object. Refer to the documentation for particular applications to get the names that may be used.
|
return: |
object - an instance of the specified COM object.
|
description: |
Create an instance of a COM object to be used in a script. When this function is used, an Automation server is started, and an instance of a COM object is established. COMCreateObject() does not get or connect to an existing instance of a COM object in another application. Rather, it starts a new instance of an object in another application.
|
see: |
#link <comobj>, COM object, COMGetObject, COMReleaseObject
|
example: |
/* This example script was tested with Word 2000 but should work with Word 97. Word does not need to be running, just installed. */
#link "comobj"
var text = "Nombas, Inc.\n" "\n" "To All ScriptEase users:\n" "\n" "The Component Object Model is very powerful " "and might be worth the time to learn how " "to use. By using Automation, " "you may automate and control many applications " "from ScriptEase scripts, as is being " "illustrated by this simple example " "of automating Word.\n";
/* These next few lines connect to a new instance of a COM object in Word. Both of the succeeding illustrations rely on these initial lines but show how to do the same thing using different approaches. Either approach is acceptable. */ var wd; wd = COMCreateObject("Word.Application"); wd.visible = true;
/* This first illustration of putting text into a Word document uses the properties of the Word.Application object and does not define any new ScriptEase variables.
Since we start a new instance of word, when we add a document, it is document 1. */ wd.documents.add; wd.documents(1).content = text;
/* This second illustration defines a new variable to point to a property of the Word.Application object and uses that variable.
When we add another document, we define the variable doc to point to it. Thus, we do not have to worry about the document number. */ var doc; doc = wd.documents.add; doc.content = text; |