OLE Control

See AlsoOXB1WZ         Properties3LY5JZM        Events21WCRBC       Methods21WKAB8


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 Object1MHI551 property.

You can create an OLE Automation object without the OLE control using the CreateObject function0M4P7F.


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.



Action04T78S3                   HelpContextID764PDR                         OleTypeAllowed633XBW1

AppIsRunning8UE005T       HostName17YIR2N                               OleType12K24M2

AutoActivate1OHYKEP         hWnd1CIW7KQ                                      Parent17GLLBF

AutoVerbMenuZQ3UT5      Index3MKW18P                                      PasteOKMF6ISM

BackColor1W9T6JQ            Left1CIZPD6                                         Picture

BorderStyle43RNRL          lpOleObject2PPS0SL                             SizeMode2KW9BMO

ClassVN4BZO                   Name2016V9P                                      SourceDoc4200A12

Data2W08UX1                     ObjectAcceptFormatsCountCGOYZQ     SourceItemZ9ATER

DataTextMBTZNK              ObjectAcceptFormatsOSMY8L              Tag6GI6KP

DisplayTypeB9TGQJ         ObjectGetFormatsCountDDT1TX          Top1CIZPD6

DragIcon3G3M07O              ObjectGetFormats1CNFCPK                   UpdateOptionsUKX64L

DragModeS9LGP1            Object1MHI551                                     Verb2W0JYV2

FileNumber349SJPB           ObjectVerbFlags11EPAR5                     Visible32KNZA4

Format23FQAYP                 ObjectVerbsCountKJ051S                   WidthL14VJZ

HeightL14VJZ                  ObjectVerbs4JYBHV




Click68UQAKP                    KeyDownRI06O6                     MouseMove1D70SW5

DblClick2UG5QK1               KeyPressPFFDUA                    MouseUpD0VNMJ

DragDrop1EBOJGL             KeyUpRI06O6                         Resize2WM7WLP

DragOver2TUGMAC             LostFocus2ZXQDAR                   Updated6A7MQD

GotFocus32EWUCC             MouseDownD0VNMJ









See Also


CreateObject Function0M4P7F

GetObject FunctionTLKUVF

Open Statement103I7PS

Using Custom ControlsHOWOLE


Programmer's Guide:

Chapter 22, "Object Linking and Embedding (OLE)"

Chapter 23, "Programming Other Applications' Objects"