Microsoft KB Archive/262987

= How To Automate FrontPage to Create a New Web and Set a Navigation Structure =

Article ID: 262987

Article Last Modified on 1/27/2007

-

APPLIES TO


 * Microsoft Office FrontPage 2003
 * Microsoft FrontPage 2002 Standard Edition
 * Microsoft FrontPage 2000 Standard Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q262987



SUMMARY
This article demonstrates how to automate Microsoft FrontPage to create a new FrontPage Web, add blank HTML pages, set a navigation structure, and insert HTML in existing pages.



MORE INFORMATION
Follow these steps to create the sample:  Start Visual Basic and create a new Standard EXE project. Form1 is created by default. On the Project menu, click References to bring up the References dialog box. For Office FrontPage 2003, select &quot;Microsoft FrontPage 6.0 Web Object Reference Library&quot; and &quot;Microsoft FrontPage 6.0 Page Object Reference Library&quot;. For FrontPage 2002, select the &quot;Microsoft FrontPage 5.0 Web Object Reference Library&quot; and the &quot;Microsoft FrontPage 5.0 Page Object Reference Library&quot;. For FrontPage 2000, select the &quot;Microsoft FrontPage 4.0 Web Object Reference Library&quot; and the &quot;Microsoft FrontPage 4.0 Page Object Reference Library&quot;. Click OK to close the dialog box. Add a CommandButton control to Form1.  In the code window for Form1, insert the following code: Option Explicit ' Define constants Const Servername = &quot;http://ServerName&quot; Const FPWebFolder = &quot;FPTest&quot;

Private Sub Command1_Click Dim oFPweb As Frontpage.Web Dim oFP As Frontpage.Application ' Create an instance of FrontPage Set oFP = CreateObject(&quot;Frontpage.Application&quot;) ' Create a new web Set oFPweb = oFP.Webs.Add(Servername & &quot;/&quot; & FPWebFolder) ' Show FrontPage oFPweb.Activate ' Add 3 new files With oFPweb.RootFolder.Files .Add &quot;default.htm&quot; .Add &quot;temp1.htm&quot; .Add &quot;temp2.htm&quot; End With ' Apply the navigation structure to the web ApplyNavigationStructure oFP

' Add comments to each of the files AddCommentToFile oFP, &quot;default.htm&quot; AddCommentToFile oFP, &quot;temp1.htm&quot; AddCommentToFile oFP, &quot;temp2.htm&quot;

' 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 &quot;temp1.htm&quot;, &quot;Child #1 (temp1.htm)&quot;, fpStructLeftmostChild oNavNode.children.Add &quot;temp2.htm&quot;, &quot;Child #2 (temp2.htm)&quot;, 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 & &quot;/&quot; & FPWebFolder & _                &quot;/_borders/left.htm&quot;, fpPageViewDefault) oPagewin.Activate ' Get the Document object Set oFPdoc = oPagewin.Document ' Look for the &quot;Navigation&quot; webbot For Each oBot In oFPdoc.All.tags(&quot;webbot&quot;) If oBot.getBotAttribute(&quot;bot&quot;) = &quot;Navigation&quot; Then ' Add a link to the home page to the navigation bot Call oBot.setBotAttribute(&quot;b-include-home&quot;, &quot;TRUE&quot;) 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 & &quot;/&quot; & FPWebFolder & &quot;/&quot; & filename, fpPageViewDefault) oPagewin.Activate ' Get the document object Set oFPdoc = oPagewin.Document ' Replace the HTML with the commented HTML oFPdoc.body.outerHTML = &quot; This file is &quot; & filename & &quot; &quot; ' Save the page oPagewin.Save True ' Close the page oPagewin.Close End Sub NOTE: In the preceding code, modify the constant &quot;ServerName&quot; to be the name of your Web Server.

 Press the F5 key to run the project.

