VBA示例

Sub DisplaySubTree()
'Returns the subtree of a given node
Dim objApp As FrontPage.Application
Dim objNavNode As NavigationNode
Dim objNavNodes As NavigationNodes
Dim objSubTree As NavigationNodes
Dim objSubNode As NavigationNode
Dim strAns As String 'User input
Dim blnFound As Boolean 'Boolean found flag
Dim intCount As Integer 'Integer counter
Dim strSubNodes As String 'Names of all sub nodes
blnFound = False
intCount = 0
Set objApp = FrontPage.Application
'Create a reference to the NavigationNodes collection
Set objNavNodes = objApp.ActiveWeb.AllNavigationNodes
'Prompt the user to enter the name of the node
strAns = InputBox("Enter the name of the node for which " & _
" you want to view the subtree.")
'While the node is not found and there are more nodes in the tree
Do While (Not blnFound = True) And (intCount <= objNavNodes.Count - 1)
'Compare user input with node label
If Trim(strAns) = objNavNodes.Item(intCount).Label Then
'If found, return node
Set objNavNode = objNavNodes.Item(intCount)
'Set found flag to true
blnFound = True
Else
'Otherwise increase counter, keep checking
intCount = intCount + 1
End If
Loop
If blnFound = True Then
Set objSubTree = objNavNode.SubTree
For Each objSubNode In objSubTree
'If the string is empty or has not yet been set
If strSubNodes = "" Then
strSubNodes = strSubNodes & objSubNode.Label
Else
'otherwise add next node lable to string
strSubNodes = strSubNodes & ", " & vbCr & objSubNode.Label
End If
Next objSubNode
'Display names of all nodes in subtree
MsgBox "The nodes found in the subtree of " & objNavNode.Label & " are: " _
& vbCr & vbCr & strSubNodes & "."
Else
'If not found, display message to user
MsgBox "The navigation node " & strAns & " was not found."
End If
End Sub