Option Explicit
' Define constants
Const Servername = "http://ServerName"
Const FPWebFolder = "FPTest"
Private Sub Command1_Click()
Dim oFPweb As Frontpage.Web
Dim oFP As Frontpage.Application
' Create an instance of FrontPage
Set oFP = CreateObject("Frontpage.Application")
' Create a new web
Set oFPweb = oFP.Webs.Add(Servername & "/" & FPWebFolder)
' Show FrontPage
oFPweb.Activate
' Add 3 new files
With oFPweb.RootFolder.Files
.Add "default.htm"
.Add "temp1.htm"
.Add "temp2.htm"
End With
' Apply the navigation structure to the web
ApplyNavigationStructure oFP
' Add comments to each of the files
AddCommentToFile oFP, "default.htm"
AddCommentToFile oFP, "temp1.htm"
AddCommentToFile oFP, "temp2.htm"
' Set variables to nothing and shut down FrontPage
' by calling oFP.WebWindows.Close
Set oFPweb = Nothing
oFP.WebWindows.Close
Set oFP = Nothing
End Sub
Private Sub ApplyNavigationStructure(oFP As Frontpage.Application)
Dim oPagewin As Frontpage.PageWindow
Dim oFPdoc As FrontpageEditor.IHTMLDocument2
Dim oBot As FrontpageEditor.FPHTMLFrontpageBotElement
Dim oNavNode As Frontpage.NavigationNode
' Get the home page navigation node
Set oNavNode = oFP.ActiveWeb.HomeNavigationNode
' Add two children to the home page
oNavNode.children.Add "temp1.htm", "Child #1 (temp1.htm)", fpStructLeftmostChild
oNavNode.children.Add "temp2.htm", "Child #2 (temp2.htm)", fpStructRightmostChild
' Apply the structure
oFP.ActiveWeb.ApplyNavigationStructure
' Set the shared borders for the current web
oFP.ActiveWeb.SharedBorders = fpBorderLeft Or fpBorderBottom
' Load the _borders/left.htm file
Set oPagewin = oFP.LocatePage(Servername & "/" & FPWebFolder & _
"/_borders/left.htm", fpPageViewDefault)
oPagewin.Activate
' Get the Document object
Set oFPdoc = oPagewin.Document
' Look for the "Navigation" webbot
For Each oBot In oFPdoc.All.tags("webbot")
If oBot.getBotAttribute("bot") = "Navigation" Then
' Add a link to the home page to the navigation bot
Call oBot.setBotAttribute("b-include-home", "TRUE")
End If
Next oBot
' Save left.htm
oPagewin.Save
' Close the file
oPagewin.Close
End Sub
Private Sub AddCommentToFile(oFP As Frontpage.Application, filename As String)
Dim oPagewin As Frontpage.PageWindow
Dim oFPdoc As FrontpageEditor.IHTMLDocument2
' Load the file to be edited
Set oPagewin = oFP.LocatePage(Servername & "/" & FPWebFolder & "/" & filename, fpPageViewDefault)
oPagewin.Activate
' Get the document object
Set oFPdoc = oPagewin.Document
' Replace the HTML with the commented HTML
oFPdoc.body.outerHTML = "<body><p>This file is <b>" & filename & "</b></p></body>"
' Save the page
oPagewin.Save True
' Close the page
oPagewin.Close
End Sub