Help and Support
 

powered byLive Search

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

Article ID:262987
Last Review:January 27, 2007
Revision:3.4
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.

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:

http://support.microsoft.com/ofd (http://support.microsoft.com/ofd)

Back to the top


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

Back to the top

Keywords: 
kbautomation kbhowto KB262987

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.