That section explained how Microsoft will automatically number the navigation nodes in either FrontPage or Expression Web.

This section will give three examples of adding a new Child Node to the previous web structure with VBA

The original navigation node layout from the previous section was as follows:

 

 

Example 1.

Sub AddLeft()

   Dim objWeb As Web
   Set objWeb = Application.ActiveWeb
   Dim objFiles As WebFiles
   Set objFiles = objWeb.RootFolder.Files
   Dim strFileName As String
   Dim strLabel As String
   strFileName = "abcdefgh.htm"
   strLabel = "abcdefgh"
   objFiles.Add (strFileName)

   Call objWeb.Application.ActiveWeb. _ 
   AllNavigationNodes.Item(4). _
   Children.Add(strFileName, strLabel, _ 
   NodeLocationAsLeftmostChild)

   objWeb.ApplyNavigationStructure

End Sub

The call statement in the code above is going to add a new child to navigation node number 4.  

The last argument of "NodeLocationAsLeftmostChild" will add the new child before child 7.  The old navigation node numbers of 7 and greater will be increased by 1.

The new navigation view will look like the following.  The labels have been manually renamed to correspond directly with the node numbers. 

The new page has the navigation node number 7.
Sample Output with AddLeft

 

Example 2

We could have added the following code to the original website:

Sub AddRight()

   Dim objWeb As Web
   Set objWeb = Application.ActiveWeb
   Dim objFiles As WebFiles
   Set objFiles = objWeb.RootFolder.Files
   Dim strFileName As String
   Dim strLabel As String
   strFileName = "abcdefgh.htm"
   strLabel = "abcdefgh"
   objFiles.Add (strFileName)

   Call objWeb.Application.ActiveWeb. _ 
   AllNavigationNodes.Item(4). _
   Children.Add(strFileName, strLabel, _ 
   NodeLocationAsRightmostChild)

   objWeb.ApplyNavigationStructure

End Sub

The call statement in the code above is going to add a new child to navigation node number 4.   The last argument of "NodeLocationAsRightmostChild" will add the new child after child 9.  The old navigation node numbers of 10 and greater will be increased by 1.

The new navigation view will look like the following.  The labels have been manually renamed to correspond directly with the node numbers.  The new page has the navigation node number 10.

Sample Output with AddRight.

 

Example 3

We could have added the following code to the original website:

Sub AddChild()

   Dim objWeb As Web
   Set objWeb = Application.ActiveWeb
   Dim objFiles As WebFiles
   Set objFiles = objWeb.RootFolder.Files
   Dim strFileName As String
   Dim strLabel As String
   strFileName = "abcdefgh.htm"
   strLabel = "abcdefgh"
   objFiles.Add (strFileName)

   Call objWeb.Application.ActiveWeb. _ 
   AllNavigationNodes.Item(4). _
   Children.Add(strFileName, strLabel, _ 
   NodeLocationToRightOfSibling, 0)

   objWeb.ApplyNavigationStructure

End Sub

Notice that the Call statement above has an additional last argument of 0.  This is the left sibling argument.  The 3 siblings of the parent 4, which are node numbers 7, 8 and 9 will have sibling numbers of 0, 1 and 2. 

The argument "NodeLocationToRightOfSibling, 0 will add the new child after sibling 0 which is node 7. 

The new navigation view will look like the following.  The labels have been manually renamed to correspond directly with the node numbers.  The new page has the navigation node number 8.

Sample output for AddChild


Valid XHTML 1.0 Transitional        Valid CSS!