Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 262987 - Last Review: January 27, 2007 - Revision: 3.5
How To Automate FrontPage to Create a New Web and Set a Navigation Structure
This article was previously published under Q262987
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.
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 "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.
- Add a CommandButton control to Form1.
- 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.
- Press the F5 key to run the project.
For more information on Office Automation, please visit the
Microsoft Office Development support site at:
APPLIES TO
- Microsoft Office FrontPage 2003
- Microsoft FrontPage 2002 Standard Edition
- Microsoft FrontPage 2000 Standard Edition
- Microsoft Visual Basic 6.0 Professional Edition
| kbautomation kbhowto KB262987 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate