OLEObjects.Add Method (Excel)

Published: July 16, 2012

Adds a new OLE object to a sheet.

expression .Add(ClassType, FileName, Link, DisplayAsIcon, IconFileName, IconIndex, IconLabel, Left, Top, Width, Height)

expression A variable that represents an OLEObjects object.

Parameters

Name

Required/Optional

Data Type

Description

ClassType

Optional

Variant

(you must specify either ClassType or FileName). A string that contains the programmatic identifier for the object to be created. If ClassType is specified, FileName and Link are ignored.

Height

Optional

Variant

(you must specify either ClassType or FileName). A string that specifies the file to be used to create the OLE object.

Link

Optional

Variant

True to have the new OLE object based on FileName be linked to that file. If the object isn't linked, the object is created as a copy of the file. The default value is False.

DisplayAsIcon

Optional

Variant

True to display the new OLE object either as an icon or as its regular picture. If this argument is True, IconFileName and IconIndex can be used to specify an icon.

IconFileName

Optional

Variant

A string that specifies the file that contains the icon to be displayed. This argument is used only if DisplayAsIcon is True. If this argument isn't specified or the file contains no icons, the default icon for the OLE class is used.

IconIndex

Optional

Variant

The number of the icon in the icon file. This is used only if DisplayAsIcon is True and IconFileName refers to a valid file that contains icons. If an icon with the given index number doesn't exist in the file specified by IconFileName, the first icon in the file is used.

IconLabel

Optional

Variant

A string that specifies a label to display beneath the icon. This is used only if DisplayAsIcon is True. If this argument is omitted or is an empty string (""), no caption is displayed.

Left

Optional

Variant

The initial coordinates of the new object, in points, relative to the upper-left corner of cell A1 on a worksheet, or to the upper-left corner of a chart.

Width

Optional

Variant

The initial size of the new object, in points.

Top

Optional

Variant

The initial coordinates of the new object in points, relative to the upper-left corner of cell A1 on a worksheet, or to the upper-left corner of a chart.

Return Value

An OLEObject object that represents the new OLE object.

This example creates a new Microsoft Word OLE object on Sheet1.

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

This example adds a command button to sheet one.

Worksheets(1).OLEObjects.Add ClassType:="Forms.CommandButton.1", _ 
 Link:=False, DisplayAsIcon:=False, Left:=40, Top:=40, _ 
 Width:=150, Height:=10

Community Additions

ADD
Show:
© 2014 Microsoft