The information in this article applies to:
SYMPTOMS
When you use the CreateObject function in a Visual Basic version 3.0
procedure to create a Microsoft Excel OLE Automation object, a new
instance of Microsoft Excel starts, but you cannot see it.
WORKAROUNDIf you want to see Microsoft Excel when you use the CreateObject function to access the application object, use the Visible property as in the following example:
MORE INFORMATION
When you use the CreateObject function to run Microsoft Excel, you
start a new hidden instance of Microsoft Excel. Because this new
instance uses memory and resources on your system, you should exit
the program within the same procedure that runs the instance. If you
don't exit the program in the procedure, the invisible instance runs
until you exit Microsoft Windows.
CreateObject Versus GetObject FunctionsCreateObject and GetObject are two Visual Basic functions that you can use to return an OLE Automation object. The CreateObject function creates an OLE Automation object; the GetObject function retrieves an OLE Automation object from a file. The way an application behaves when you start it with one of these functions depends on the application. For example, when you use the CreateObject function to access a Microsoft Excel Application object, an invisible instance of Microsoft Excel runs. When you use the CreateObject function to access a Microsoft Word WordBasic object, a visible instance of Microsoft Word runs.Use the following list to determine the behavior of Microsoft Excel when you use the CreateObject or GetObject function:
Microsoft Word for WindowsWhen you use the CreateObject function to access a Microsoft Word for Windows WordBasic object, a new visible instance runs if Word for Windows is not currently running. If you set the variable returned by the CreateObject function equal to nothing in this case, Word for Windows is closed. Otherwise, if Word for Windows is already running, the CreateObject function uses the running instance. If you set the variable returned by the CreateObject function equal to nothing in this case, Word for Windows is not closed, because the instance was running before you ran the procedure.Note that in Word for Windows 95, version 7.0, an invisible instance is run rather than a visible one. The following Visual Basic procedure uses the CreateObject function to access the Word for Windows WordBasic object, performs some Word commands, and then sets the OLE Automation object variable equal to Nothing.
NOTE: The above information applies both to Visual Basic version 3.0, and
Visual Basic for applications. However, because Microsoft Excel has an
object library, use the functions defined in that library when you access
Microsoft Excel objects in a Visual Basic, Applications Edition procedure,
rather than the GetObject or CreateObject function. Because Microsoft Word
for Windows does not have an object library, you must use the CreateObject
or GetObject function to access a Microsoft Word object in any version of
Visual Basic.
Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide." For more information on the GetObject function, query on the following words in the Microsoft Knowledge Base: ole and automation and getobject REFERENCESFor more information about the GetObject Function and the CreateObject Function, choose the Search button in the Visual Basic Reference and type: OLE Automation Additional query words: 7.00 officeinterop Word6 B_VBasic
Keywords : kbprg |
Last Reviewed: October 14, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |