HTMLProjectItem Object

Microsoft Office Visual Basic

HTMLProjectItemsHTMLProjectItem

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 document.

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

Use the Open method to open a project item in source view or text view, and use the IsOpen property to determine whether the project item is currently open. The following example opens the project item named “ItemOne” (in the active document) in the default view and then displays a message box stating whether the item was opened successfully.

ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne").Open
If ActiveDocument.HTMLProject. _
        HTMLProjectItems("ItemOne").IsOpen Then
MsgBox "Opened project item " & ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne").Name
End If
		

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

ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne") _
    .Open (msoHTMLProjectOpenTextView)
ActiveDocument.HTMLProject.HTMLProjectItems("ItemOne") _
    .SaveCopyAs("C:\NewItem.txt")
		

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

MsgBox ActiveDocument.HTMLProject.HTMLProjectItems _
    ("ItemOne").Text
ActiveDocument.HTMLProject.HTMLProjectItems _
    ("ItemOne").LoadFromFile("C:\NewText.txt")
MsgBox ActiveDocument.HTMLProject.HTMLProjectItems _
    ("ItemOne").Text