NavigationNode Object

See Also         Properties         Methods        

Application object
Webs object
Web object
RootNavigationNode object
NavigationNodes collection (NavigationNode)
Represents a node in the navigation structure of a web. The NavigationNode object is a member of the NavigationNodes collection. Within the NavigationNodes collection, individual NavigationNode objects are indexed beginning with zero.

Important   From the NavigationNode object, you can access all other navigation nodes in a web. The RootNavigationNode object, created by default each time you create a new web, provides the basis for the navigation structure, which is accessed through the Children property. The first child node of the navigation structure is usually the home page of the web, which can be accessed through the HomeNavigationNode property. However, the first child node of the root navigation node can be any page, and may not contain a HomeNavigationNode object at all.

Using the NavigationNode Object

You can use the NavigationNode property to return the NavigationNode object. The following example builds a list of navigation node labels for the WebFile object of the WebFiles collection.

Private Sub GetNavigationNode()
Dim myWeb As Web
Dim myWebFiles As WebFiles
Dim myWebFile As WebFile
Dim myNavNodeLabel As String
Dim myLabel As String

On Error Resume Next

Set myWeb = ActiveWeb
Set myFiles = myWeb.RootFolder.Files

With myFiles
    For Each myFile In myFiles
        myLabel = myFile.NavigationNode.Label
        If Err <> 0 Then Exit Sub
        myNavNodeLabel = myNavNodeLabel & myLabel & vbCRLF
    Next
End With
End Sub

The Children property returns the collection of child nodes within the navigation structure of a web. The following statement returns the number of child nodes within the navigation structure of the active web.

myNavChildrenCount _
    = ActiveWeb.RootFolder.Files(0).NavigationNode.Children.Count

Use Children(index), where index is the index number of a navigation node item, to return a single NavigationNode object. The following statement returns the file name of the first navigation node in the NavigationNodes collection.

myNavNodeName _
    = ActiveWeb.RootFolder.Files(0).NavigationNode.Children(0).File.Name

The File property returns the File object that is associated with the NavigationNode object. The following statement returns True if the file is open.

myNavFile = ActiveWeb.RootFolder.Files(3).NavigationNode.File.IsOpen

The Home property returns the Home object associated with the current navigation node and references information such as the Children, File, Label, Next, Prev, and other properties for the home page. The following statement returns the URL of the Home property for the NavigationNode object.

myHomePageUrl _
    = ActiveWeb.RootFolder.Files(5).NavigationNode.Home.Url

You can return the Label property to set or return text that can be used as buttons within the navigation structure, or used for text in a navigation bar. The following example returns the label for the home page.

myLabel = ActiveWeb.RootFolder.Files(0).NavigationNode.Label

Use the Next, Parent, Prev, or Url properties to return navigation nodes associated with the specified property. The following example returns the URL that is associated with the previous NavigationNode object.

myPrevNode = ActiveWeb.RootFolder.Files(1).NavigationNode.Prev.Url

Use the Web property to return the Web object associated with the current navigation node. The following example returns the Web object for the current navigation node.

myNavNodeWeb = _
    ActiveWeb.RootFolder.Files(2).NavigationNode.Web.Url

Use the Move method to move a navigation node from one child node to another. The following example moves a navigation node to a child location on a sibling node in the same web.

Private Sub MoveNavNode()
Dim myNodes As NavigationNodes
Dim myNode As NavigationNode

Set myNodes = ActiveWeb.RootNavigationNode.Children
Set myNode = myNodes(4)

myNode.Move myNodes, myNodes(2)
ActiveWeb.ApplyNavigationStructure
End Sub