Special Edition Using Microsoft Office FrontPage 2003
Now that you have a general understanding of the pieces that make up a VBA macro, let's take a look at how we can use a macro to automate FrontPage. When you write macros, you access parts of the application you're developing against using a predefined set of classes, properties, and methods called an object model. FrontPage actually has three different object models that you can use; the Application object model, the Web object model, and the Page object model. As you might have guessed, you access the FrontPage application using the Application object model, you access Web sites with the Web object model, and you access Web pages and their content using the Page object model. The Application Object Model
The top-level object in the Application object model is the Application object. The Application object represents the current instance of the FrontPage application itself. Suppose that we want to display the version of FrontPage that we are running. We can do that using the following code:
MsgBox Application.Version This code displays the Version property of the Application object in a message box. The Web Object Model
At the core of the Web object model is the WebEx object. A WebEx object represents a FrontPage Web site. You can get a reference to a WebEx object as follows:
1 Dim oWeb As WebEx 2 Set oWeb = Webs.Open("http://localhost", , fpOpenInWindow) Line numbers are included for reference only and are not part of the code. In the first line we declare a variable called oWeb and indicate that it will contain a WebEx object. We then open the Web site located at http://localhost and set the oWeb object equal to that Web site. After this code executes, oWeb will contain a reference to the root Web on the local machine and we can begin accessing the properties of that site and calling its methods. For example, suppose that we want to publish the root Web of the local machine to http://www.mysite.com. We can do that using the code in Listing 30.1. Listing 30.1 Publishing to Root Web
1 Dim oWeb As WebEx 2 Set oWeb = Webs.Open("http://localhost", , fpOpenInWindow) 3 oWeb.Publish "http://www.mysite.com", fpPublishAddToExistingWeb As you can see, writing code to automate functionality in FrontPage is easy once you get the hang of it.
The Page Object Model
Now that we've got a WebEx object, we can easily access that Web site's files by using the WebFile object. If, for example, we wanted to open the page called default.htm in the root folder of the Web site, we would do it by adding the code in Listing 30.2 to the code we entered in Listing 30.1. Listing 30.2 Opening Page from Root
1 Dim oFile As WebFile 2 Set oFile = oWeb.RootFolder.Files("default.htm") 3 oFile.Open |