Workbook.InsertFolder

Use this function to insert a folder into the workbook.

Syntax Parameters Return value
Function Workbook.InsertFolder( _
    ItemReference As WorkbookItem, _
    Optional Placement As WorkbookPlacement = scWorkbookDefaultPlacement) As WorkbookItem
  • 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 a folder 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 newfolder As WorkbookItem
    'assigns/inserts the new folder into the 
    'root folder of the workbook as the first child
    Set newfolder = wb.InsertFolder(wb.Root,scWorkbookFirstChild)
    'sets the name of the folder to Example Folder
    newfolder.Name = "Example Folder"
    'sets the workbook to visible
    wb.Visible = True
End Sub