OLE Embedding & Linking Word for Windows Objects into VB AppsID: Q97618
|
This article shows by example how to use the object linking and embedding
(OLE) client custom control (OLECLIEN.VBX) with Microsoft Word for Windows.
The example demonstrates both how to embed and how to link a Word for
Windows document into a Visual Basic application.
NOTE: In Word for Windows, version 6.0 or 6.0a, the Bookmark menu item
moved from the Insert menu to the View menu.
Embedding an object encapsulates the data displayed in the Visual Basic OLE
client control and makes the data inaccessible to other applications,
unlike the data in an linked object. In addition, embedding an object does
not require that a file already exist for the object to be usable.
Linking an object, on the other hand, does require that a file already
exist, and it requires a LinkItem setting. For a Word for Windows document,
the LinkItem can be any bookmark within the document.
The example shown below demonstrates how to use:
Property Value
----------------------------
Class "WordDocument"
Protocol "StdFileEditing"
Property Value
-------------------------------------------------------------
SourceDoc The full path of the document to use (such as
C:\OLETEST.DOC)
SourceItem A bookmark (OLE_Link is used in this example)
Default Name Caption Name
----------------------------------------------------
OleClient1 N/A OleClient1
Option1 &Embed Object OptionEmbed
Option2 &Link Object OptionLink
Command1 Embed WinWord Object Command1
Dim fshowing As Integer
Const OLE_LINKED = 0
Const OLE_EMBEDDED = 1
Const OLE_STATIC = 2
Const OLE_CREATE = 0
Const OLE_CREATE_FROM_FILE = 1
Const OLE_UPDATE = 6
Const OLE_ACTIVATE = 7
Const OLE_DELETE = 10
Sub Command1_Click ()
' Unload the current object so a new object can be loaded
If fshowing Then
OleClient1.Action = OLE_DELETE
End If
OleClient1.Class = "WordDocument"
OleClient1.Protocol = "StdFileEditing"
If OptionEmbed Then
' Data is managed by Visual Basic
OleClient1.ServerType = OLE_EMBEDDED
OleClient1.Action = OLE_CREATE
Else
OleClient1.SourceDoc = "C:\OLETEST.DOC"
OleClient1.SourceItem = "OLE_Link"
OleClient1.ServerType = OLE_LINKED
OleClient1.Action = OLE_CREATE_FROM_FILE
End If
OleClient1.Action = OLE_UPDATE
fshowing = True
End Sub
Sub OleClient1_DblClick ()
OleClient1.Action = OLE_ACTIVATE
End Sub
Sub OptionEmbed_Click ()
Command1.Caption = "Embed WinWord Object"
End Sub
Sub OptionLink_Click ()
Command1.Caption = "Link WinWord Object"
End Sub
Additional query words: noupd
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 1, 1999