To manipulate embedded or linked objects, the OLE Container control provides the following methods, in addition to the properties already mentioned.
Create Embed
This method creates an embedded object. It has the following syntax:
CreateEmbed sourcedoc, class
The sourcedoc argument is the filename of a document used as a template for the embedded object. To create a new embedded document, supply a zero-length string (‘III) for the sourcedoc argument.
The class argument is an optional argument that specifies the name of the class of the embedded object. This argument is required only if the sourcedoc argument is omitted. To find out the registered classes, select the OLE Container control’s Class property in the Properties window and click the button with the ellipsis.
Create Link
This method creates a linked object from the contents of a file. It has the following syntax:
CreateLink sourcedoc, sourceitem
The sourcedoc.document is the file from which the object will be created, and sourceitem is the data within ‘the file to be linked in the linked object. For example, to link the contents of the OLE Container control to a range of Excel cells, specify the file with the sourcedoc argument and the range of cells to be linked with the sourceitem argument. The sourceitem argument can be a single cell, such as RIOC12,or a range of cells, such as RICl:RlOC20. You can also specify a named range.
After the linked document is created, the Sourceltem property is reset to a zero length string, and its original value is appended to the SourceDoc property, which becomes something like the following:
“c:\data\revenus\rev1997.xls / RlCl:R20C25”
An easy way to determine the syntax of the two commands is to select the object you want to link (or a similar one) and then paste it with the Paste Special command on the OLE Container control at design time. After the object is linked, look up the value of the SourceDoc property and use it in your code.
DoVerb verb
The DoVerb method executes a command (which is a verb like Edit, Play and so on). The object knows how to carry out the command The optional verb argument can have one of the values in Table.
Insert Obj Dlg
This method displays the Insert Object dialog box. The user’s selections are reported to the application via the properties of the OLE Container control.
Paste Special Dlg
This method displays the Paste Special dialog box. The user’s selections are reported. to the application via the OLE Container control’s properties.
To find out the intrinsic constants you can use with the various methods and properties of the OLE Container control, use the Object Browser.
1. Choose View >Object Browser,
2. Select the Visual Basic object library, and then choose the Constants object to display the names of the constants under Methods/Properties.
If you experiment a little with OLE techniques and the OLE Container control, you’ll realize that OLE is still rough around the edges. You don’t have complete. . control over the appearance of the embedded or linked object, and sometimes the .server application’s toolbars are not visible. In general, OLE is not quite mature even though it’s been around for a few years.
In reality, not many Visual Basic applications embed and link documents provided by server applications. However, there’s another aspect of OLE, OLE Automation, which has matured and is one of the most powerful features of major Windows applications such as the Office application. We’ll discuss OLE Automation in the second half of the chapter, but first let’s look briefly at OLE drag-and-drop operations.