Word for Windows Supports OLE Automation as a Server Only

Last reviewed: February 6, 1998
Article ID: Q105535
The information in this article applies to:
  • Microsoft Word for Windows, version 6.0

SUMMARY

Object linking and embedding (OLE) Automation is a Windows protocol that allows an application to share data or control another application. Word for Windows provides other applications with an object called "Basic". Using this object, other applications can send WordBasic instructions to Word for Windows.

Applications that support OLE Automation, such as a Visual Basic 3.0 application or Excel 5.0, can use OLE Automation with Word, but Word cannot use OLE Automation to access other applications. Using DDE terms, this means that Word can act as a server for another application but cannot act as the client.

Visual Basic 3.0 Example

To control Word for Windows from a Visual Basic application, you need to first declare a variable of type Object. For example:

   Dim WordObj As Object

Next, you need to create the "Basic" object and assign it to the object variable. For example:

   Set WordObj =CreateObject("Word.Basic")

The above statement makes the "Basic" object in Word available to Visual Basic for OLE Automation. If Word for Windows is not running, OLE Automation will attempt to start the application using the information found in the Windows registration file (REG.DAT).

The following Visual Basic example opens a new Word document, changes the formatting at the insertion point to Arial 22 pt bold and inserts the text "Hello World":

   Sub Command1_Click ()
   Dim WordObj As Object
   Set WordObj = CreateObject("Word.Basic")
   WordObj.filenew
   WordObj.FormatFont 22, , , , , , , , , , , , , , , "Arial", 1
   WordObj.Insert "Hello World"
   End Sub

The following Excel 5.0 example, opens a new Word document, changes the formatting at the insertion point to Arial, 22 pt, bold and inserts the text "Hello World".

Sub Main()
 Dim WordObj As Object
 Set WordObj = CreateObject("Word.Basic")
 WordObj.FileNew
 WordObj.FormatFont Font:="Arial", Points:=22, Bold:=1
 WordObj.Insert "Hello World"
End Sub

REFERENCES

"Microsoft Word Developer's Kit," pages 174-182 "Microsoft Excel Visual Basic User's Guide," Chapter 10


KBCategory: kbmacro
KBSubcategory:
Additional query words: 6.0 ole automation word basic word6
winword object container server
Keywords : kbole kbmacro
Version : 6.0
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.