See Also Properties Events Methods
Description
Object linking and embedding (OLE) is a technology that allows a programmer of Windows-based applications to create an application that can display data from many different applications, and allows the user to edit that data from within the application in which it was created. In some cases, the user can even edit the data from within the Visual Basic application. The Visual Basic OLE control provides an interface to this technology.
Using the OLE Control
You use the OLE control to display an OLE object on a form. You either create the object at design time using standard OLE dialogs (Insert Object, Paste Special), or at run time by setting the appropriate properties.
Using the OLE Control's Pop-up Menus
Each time you draw an OLE control on a form, the Insert Object dialog is displayed. You use this dialog to create a linked or embedded object. By choosing Cancel, an object is not created.
At design time, you click the OLE control with the right mouse button to display a pop-up menu. The commands displayed on this pop-up menu depend on the state of the OLE control as displayed in the following table:
Command Enabled in pop-up when...
Insert Object this command is always enabled.
Paste Special the Clipboard contains a valid OLE object.
Delete Embedded Object the OLE control contains an embedded object.
Delete Linked Object the OLE control contains a linked object.
Create Link the SourceDoc property is set.
Create Embedded Object the Class or SourceDoc property is set.
OLE Fundamentals
The following terms and concepts are fundamental to understanding the OLE control.
OLE Object
An OLE object refers to a discrete unit of data supplied by an OLE application. An application can expose many types of objects. For example a spreadsheet application can expose a worksheet, macro sheet, chart, cell, or range of cellsall as different types of objects.
You use the OLE control to create linked and embedded objects. When a linked or embedded object is created, it contains the name of the application that supplied the object, its data (or, in the case of a linked object, a reference to the data), and an image of the data. An OLE control can contain only one object at a time. There are several ways to create a linked or embedded object:
Use the Insert Object or Paste Special dialogs (run time and design time).
Set the Class property in the Properties window, then click the OLE control with the right mouse button and select the appropriate command (design time only).
Set the Action property of the OLE control (run time only).
OLE Automation
Some applications provide objects that support OLE Automation. You can use Visual Basic to programmatically manipulate the data in these objects. Some objects that support OLE Automation also support linking and embedding. If an object in the OLE control supports OLE Automation, you can access its data using the Object property.
You can create an OLE Automation object without the OLE control using the CreateObject function
Class
An objects class determines the application that provides the objects data and the type of data the object contains. The class names of some commonly used Microsoft applications include MSGraph, MSDraw, WordDocument, and ExcelWorksheet. You can get a list of the class names available to your application by selecting the Class property in the Properties window and clicking on the three dots in the Settings box.
Note The Insert Object dialog does not display a list of class names. This dialog displays user-friendly names for each class of object, which are generally longer and more easily understood.
Container Application
An application that receives and displays an objects data is a container application. For example, a Visual Basic application that uses an OLE control to embed or link data from another application is a container application.
In Visual Basic 2.0, applications that provide access to objects were called server or source applications. Applications used to contain objects were referred to as client or destination applications.
Linked and Embedded Objects
You use an OLE control to incorporate data into a Visual Basic application by linking or embedding data from another application. Data associated with a linked object is stored by the application that supplied the object; the OLE control stores only link references that enable display of snapshots of the source data. Data associated with an embedded object is contained in an OLE control and can be saved by your Visual Basic application.
When an object is linked, the object's data can be accessed from any application containing a link to that data and can be changed from within any of them. For example, if a text file is linked to a Visual Basic application, it can be modified by any other application linked to it. The modified version will appear in all the documents linked to this text file.
When you use an OLE control to create an embedded object, all the data associated with the object is contained in the OLE control. For example, if a spreadsheet were an embedded object, all the data associated with the cells would be contained in the OLE control, including any necessary formulas. The name of the application that created the object is saved along with the data. If the user selects the embedded object while working with the Visual Basic application, the spreadsheet application can be started automatically for editing those cells. When an object is embedded into an application, no other application has access to the data in the embedded object. Embedding is useful when you want only your application to maintain data that is produced and edited in another application.
Action HelpContextID OleTypeAllowed AppIsRunning HostName OleType AutoActivate hWnd Parent AutoVerbMenu Index PasteOK BackColor Left Picture BorderStyle lpOleObject SizeMode2KW9BMO Class Name SourceDoc Data ObjectAcceptFormatsCount SourceItem DataText ObjectAcceptFormats Tag DisplayType ObjectGetFormatsCount Top DragIcon ObjectGetFormats UpdateOptions DragMode Object Verb FileNumber ObjectVerbFlags Visible Format ObjectVerbsCount Width Height ObjectVerbs |
Click KeyDown MouseMove DblClick KeyPress MouseUp DragDrop KeyUp Resize DragOver LostFocus Updated GotFocus MouseDown |
Drag
Move
Refresh
SetFocus
ZOrder
Help:
CreateObject Function
GetObject Function
Open Statement
Using Custom Controls
Programmer's Guide:
Chapter 22, "Object Linking and Embedding (OLE)"
Chapter 23, "Programming Other Applications' Objects"