OLE Embedding & Linking Word for Windows Objects into VB AppsLast reviewed: July 20, 1995Article ID: Q97618 |
The information in this article applies to:
- Professional Edition of Microsoft Visual Basic for Windows, version 2.0 - Microsoft Word for Windows, version 2.0
SUMMARYThis 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.
MORE INFORMATIONEmbedding 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"In addition, linked objects require the following OLE client control property settings:
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)Here are the steps you need to follow to create the example:
Step One: Create the Word for Windows Document You Want to Link Or Embed1. Start Word for Windows. Document1 is created by default.
Step Two: Create the Visual Basic Application That Will Hold the Document1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N)if Visual Basic is already running. Form1 is created by default.
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 the Object in OleClient1. The Word for Windows icon is painted in the OleClient1 control. the text you entered. client control, however it is now linked to the document created in the first part of this example, not the embedded object. redisplay the text you entered in the first document. |
Additional reference words: noupd 2.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |