HTMLProjectItem Object

                  Properties         Methods

Application object
Workbooks collection (Workbook object)
HTMLProject object
HTMLProjectItems collection (HTMLProjectItem) object

Represents an individual project item that’s a project item branch in the Project Explorer in the Microsoft Script Editor. The HTMLProjectItem object is a member of the HTMLProjectItems collection.

Using the HTMLProjectItem Object

Use HTMLProjectItems(index), where index is the name or index number of a project item, to return a single HTMLProjectItem object. Use the Name property to return the display name of the project item. The following example returns the name of the first project item in the HTMLProjectItems collection for the active workbook.

MsgBox ("The first item is " & _
    ActiveWorkbook.HTMLProject _
    .HTMLProjectItems(1).Name)

Use the Open method to open a project item in the default view, and use the IsOpen property to determine whether you can view the project item in Designer view, Source view, or Preview view. The following example opens the project item named “Sheet1” (in the active workbook) in the default view and then displays a message box stating whether the item was opened successfully.

With ActiveWorkbook.HTMLProject.HTMLProjectItems("Sheet1")
    .Open
    If .IsOpen Then
        MsgBox ("Opened project item " & .Name)
    End If
End With

Use the SaveCopyAs method to save the project item using a new file name. The following example saves a copy of Sheet1 as “New”.

With ActiveWorkbook.HTMLProject.HTMLProjectItems("Sheet1")
    .Open
    .SaveCopyAs("C:\New.xls")
End With

Assuming that the text file C:\New.xls exists, the following example uses the LoadFromFile method to set the text of Sheet1 to the text contained in the file. The example uses the Text property to display the new text in a message box.

With ActiveWorkbook.HTMLProject.HTMLProjectItems("Sheet1")
    MsgBox .Text
    .LoadFromFile("C:\New.xls")
    MsgBox .Text
End With