Microsoft KB Archive/105535: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 22: Line 22:
== SUMMARY ==
== 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 &quot;Basic&quot;. Using this object, other applications can send WordBasic instructions to Word for Windows.<br />
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.<br />
<br />
<br />
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.
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.
Line 31: Line 31:


<pre class="CODESAMP">Dim WordObj As Object </pre>
<pre class="CODESAMP">Dim WordObj As Object </pre>
Next, you need to create the &quot;Basic&quot; object and assign it to the object variable. For example:
Next, you need to create the "Basic" object and assign it to the object variable. For example:


<pre class="CODESAMP">Set WordObj =CreateObject(&quot;Word.Basic&quot;) </pre>
<pre class="CODESAMP">Set WordObj =CreateObject("Word.Basic") </pre>
The above statement makes the &quot;Basic&quot; 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).<br />
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).<br />
<br />
<br />
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 &quot;Hello World&quot;:
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":


<pre class="CODESAMP">  Sub Command1_Click ()
<pre class="CODESAMP">  Sub Command1_Click ()
   Dim WordObj As Object
   Dim WordObj As Object
   Set WordObj = CreateObject(&quot;Word.Basic&quot;)
   Set WordObj = CreateObject("Word.Basic")
   WordObj.filenew
   WordObj.filenew
   WordObj.FormatFont 22, , , , , , , , , , , , , , , &quot;Arial&quot;, 1
   WordObj.FormatFont 22, , , , , , , , , , , , , , , "Arial", 1
   WordObj.Insert &quot;Hello World&quot;
   WordObj.Insert "Hello World"
   End Sub </pre>
   End Sub </pre>
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 &quot;Hello World&quot;.
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".


<pre class="CODESAMP">Sub Main()
<pre class="CODESAMP">Sub Main()
  Dim WordObj As Object
  Dim WordObj As Object
  Set WordObj = CreateObject(&quot;Word.Basic&quot;)
  Set WordObj = CreateObject("Word.Basic")
  WordObj.FileNew
  WordObj.FileNew
  WordObj.FormatFont Font:=&quot;Arial&quot;, Points:=22, Bold:=1
  WordObj.FormatFont Font:="Arial", Points:=22, Bold:=1
  WordObj.Insert &quot;Hello World&quot;
  WordObj.Insert "Hello World"
End Sub </pre>
End Sub </pre>
<br />
<br />
Line 59: Line 59:
== REFERENCES ==
== REFERENCES ==


&quot;Microsoft Word Developer's Kit,&quot; pages 174-182<br />
"Microsoft Word Developer's Kit," pages 174-182<br />
&quot;Microsoft Excel Visual Basic User's Guide,&quot; Chapter 10
"Microsoft Excel Visual Basic User's Guide," Chapter 10


Additional query words: 6.0 ole automation word basic word6 winword object container server
Additional query words: 6.0 ole automation word basic word6 winword object container server

Latest revision as of 10:09, 20 July 2020

Word for Windows Supports OLE Automation as a Server Only

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

Additional query words: 6.0 ole automation word basic word6 winword object container server

Keywords : kbole kbofficeprog
Issue type :
Technology :


Last Reviewed: March 28, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.