Workbook.InsertObject

Use this function to insert the specified object into the workbook.

Syntax Parameters Return value
Function Workbook.InsertObject( _
    Object As Object, _
    ItemReference As WorkbookItem, _
    Optional Placement As WorkbookPlacement = scWorkbookDefaultPlacement) As WorkbookItem
  • Object [in]

    The object to insert into the workbook.

    Type: Object

  • ItemReference [in]

    Which item in the workbook should be used as the parent or sibling of the inserted file. The Placement parameter determines whether the inserted file is a parent or sibling of this item.

    Type:

  • Placement [in, optional]

    Integer value specifying how to place the file into the workbook with regards to the specified ItemReference.

    Type:

    Default value:

SVB Example

Inserting an item into a workbook

Option Base 1
Option Explicit
Sub Main
    Dim wb As Workbook
    'assigns the new workbook to the object wb
    Set wb = Workbooks.New("WB Example")
    Dim M As Macro
    'assigns the new macro to the object M
    Set M = Macros.New("Example Macro")
    'inserts the object, M, into the root folder of the workbook As the last child
    wb.InsertObject(M,wb.Root,scWorkbookLastChild)
    'sets the workbook to visible
    wb.Visible = True
End Sub