Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


More information

Follow these steps to create the sample:
  1. Start Visual Basic and create a new Standard EXE project. Form1 is created by default.
  2. On the Project menu, click References to bring up the References dialog box. For Office FrontPage 2003, select "Microsoft FrontPage 6.0 Web Object Reference Library" and "Microsoft FrontPage 6.0 Page Object Reference Library". For FrontPage 2002, select the "Microsoft FrontPage 5.0 Web Object Reference Library" and the "Microsoft FrontPage 5.0 Page Object Reference Library". For FrontPage 2000, select the "Microsoft FrontPage 4.0 Web Object Reference Library" and the "Microsoft FrontPage 4.0 Page Object Reference Library". Click OK to close the dialog box.
  3. Add a CommandButton control to Form1.
  4. In the code window for Form1, insert the following code:
    
    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
    					
    NOTE: In the preceding code, modify the constant "ServerName" to be the name of your Web Server.

  5. Press the F5 key to run the project.

↑ Back to the top


References

For more information on Office Automation, please visit the Microsoft Office Development support site at:


↑ Back to the top


Keywords: KB262987, kbhowto, kbautomation

↑ Back to the top

Article Info
Article ID : 262987
Revision : 8
Created on : 1/27/2007
Published on : 1/27/2007
Exists online : False
Views : 375