Class OLEObject (Excel VBA)

The class OLEObject represents an ActiveX control or a linked or embedded OLE object on a worksheet.

The main procedures of class OLEObject are Activate, Copy, Delete, Select, OLEObjects.Add, OLEObjects.Copy, OLEObjects.Delete and OLEObjects.Select

Set

To use a OLEObject class variable it first needs to be instantiated, for example

Dim oleob as OLEObject
Set oleob = ActiveChart.OLEObjects(Index:=1)

The following procedures can be used to set variables of type OLEObject: Duplicate, OLEObjects.Item, OLEObjects.Add, Chart.OLEObjects, OLEObjects.Duplicate and Worksheet.OLEObjects

For Each

Here is an example of processing the OLEObject items in a collection.

Worksheets("Sheet1").Activate 
Range("A1").Value = "Name" 
Range("B1").Value = "Link Status" 
Range("C1").Value = "AutoUpdate Status" 
i = 2 
For Each obj In ActiveSheet.OLEObjects 
 Cells(i, 1) = obj.Name 
 If obj.OLEType = xlOLELink Then 
 Cells(i, 2) = "Linked" 
 Cells(i, 3) = obj.AutoUpdate 
 Else 
 Cells(i, 2) = "Embedded" 
 End If 
 i = i + 1 
Next

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Cell with its procedures BottomRightCell, LinkedCell and TopLeftCell
Copy with its procedures Copy, CopyPicture, OLEObjects.Copy and OLEObjects.CopyPicture
Enable with its procedures Enabled and OLEObjects.Enabled
Print with its procedures PrintObject and OLEObjects.PrintObject
Name with its procedures SourceName and OLEObjects.SourceName
Sort/Order with its procedures ZOrder and OLEObjects.ZOrder

Methods

These are the main methods of the OLEObject class

Activate - Activates the object.

ActiveChart.OLEObjects(1).Activate

Delete - Deletes the object.

ActiveChart.OLEObjects(1).Delete

Select - Selects the object.

ActiveChart.OLEObjects(1).Select

OLEObjects.Add - Adds a new OLE object to a sheet.

ActiveWorkbook.Worksheets("Sheet1").OLEObjects.Add _ 
 ClassType:="Word.Document"

OLEObjects.Delete - Deletes the object.

ActiveChart.OLEObjects.Delete

OLEObjects.Select - Selects the object.

ActiveChart.OLEObjects.Select

Other Methods

BringToFront - Brings the object to the front of the z-order.

Cut - Cuts the object to the Clipboard or pastes it into a specified destination.

Duplicate - Duplicates the object and returns a reference to the new copy.

SendToBack - Sends the object to the back of the z-order.

Update - Updates the link.

Verb - Sends a verb to the server of the specified OLE string.

OLEObjects.BringToFront - Brings the object to the front of the z-order.

OLEObjects.Cut - Cuts the object to the Clipboard.

OLEObjects.Duplicate - Duplicates the oleobject and returns a reference to the new copy.

OLEObjects.Item - Returns a single object from a collection.

OLEObjects.SendToBack - Sends the object to the back of the z-order.

Properties

AutoLoad true if the OLE object is automatically loaded when the workbook that contains it is opened.

AutoUpdate true if the OLE object is updated automatically when the source changes. Valid only if the object is linked; its OLEType property must be xlOLELink (XlOLEType enumeration).

Border returns a Border object that represents the border of the object.

Height returns or sets a Double value that represents the height, in points, of the object.

Index returns a Long value that represents the index number of the object within the collection of similar objects.

Interior returns an Interior object that represents the interior of the specified object.

Left returns or sets a Double value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).

ListFillRange returns or sets the worksheet range used to fill the specified list box. Setting this property destroys any existing list in the list box.

Locked returns or sets a Boolean value that indicates if the object is locked.

Name returns or sets a String value representing the name of the object.

Object returns the OLE Automation object associated with this OLE object. Read-only object.

OLEType returns the OLE xloletype type. Can be one of the following XlOLEType constants: xlOLELink or xlOLEEmbed. Returns xlOLELink if the xloletype is linked (it exists outside of the file), or returns xlOLEEmbed if the xloletype is embedded (it's entirely contained within the file). Read-only Long.

Parent returns the parent object for the specified object. Read-only.

Placement returns or sets a Variant value containing an XlPlacement constant that represents the way the xlplacement is attached to the cells below it.

progID returns the programmatic identifiers for the object.

Shadow returns or sets a Boolean value that determines if the object has a shadow.

ShapeRange returns a ShapeRange object that represents the specified object or objects.

Top returns or sets a Double value that represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

Visible returns or sets a Boolean value that determines whether the object is visible.

Width returns or sets a Double value that represents the width, in points, of the object.

OLEObjects.AutoLoad true if the OLE object is automatically loaded when the workbook that contains it is opened.

OLEObjects.Border returns a Border object that represents the border of the object.

OLEObjects.Count returns a Long value that represents the number of objects in the collection.

OLEObjects.Height returns or sets a Double value that represents the height, in points, of the object.

OLEObjects.Interior returns an Interior object that represents the interior of the specified object.

OLEObjects.Left returns or sets a Double value that represents the distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart).

OLEObjects.Locked returns or sets a Boolean value that indicates if the object is locked.

OLEObjects.Parent returns the parent object for the specified object. Read-only.

OLEObjects.Placement returns or sets a Variant value containing an XlPlacement constant that represents the way the xlplacement is attached to the cells below it.

OLEObjects.Shadow returns or sets a Boolean value that determines if the object has a shadow.

OLEObjects.ShapeRange returns a ShapeRange object that represents the specified object or objects.

OLEObjects.Top returns or sets a Double value that represents the distance, in points, from the top edge of the object to the top of row 1 (on a worksheet) or the top of the chart area (on a chart).

OLEObjects.Visible returns or sets a Boolean value that determines whether the object is visible.

OLEObjects.Width returns or sets a Double value that represents the width, in points, of the object.