SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 262 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


CreateObject creates a new instance of Word even if one is already open. To use CreateObject
to create an instance of a Microsoft Office product, you call the method and pass in an argument
containing the class name of that application. The class name is a combination of the
application name plus the object type. In this case (and in most cases), our object type is
Application. All Microsoft Office products expose an Application object type.Word and Excel
provide a few other object types that can be created with CreateObject as well, as shown in
Table 8-1.
CHAPTER 8 n OFFICE INTEGRATION 291
Table 8-1.Microsoft Office Object Types
Office Application Object Type Class
Access Application Access.Application
Excel Application Excel.Application
Excel Worksheet Excel.Worksheet
Excel Chart Excel.Chart
Outlook Application Outlook.Application
PowerPoint Application PowerPoint.Application
Word Application Word.Application
Word Document Word.Document
When using any of the additional object types provided by Word or Excel, a new instance
of Word or Excel is created. To use CreateObject to open an instance of Outlook, the syntax
would be the following:
CreateObject(Outlook.Application)
CREATEOBJECT VS. GETOBJECT
Another way to return an instance of an Office application is to use the GetObject function. GetObject
differs from CreateObject in that it uses an existing instance of the application. There are a couple of
instances where GetObject may make sense for your applications.


Pages:
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274