Word for Windows Supports OLE Automation as a Server Only

ID: Q105535

The information in this article applies to:

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

Last Reviewed: February 6, 1998