Microsoft Office 2000/Visual Basic Programmer's Guide   

Understanding the Application Object

The Application object is the top-level object in the FrontPage object model. It represents FrontPage itself and provides access to all of the objects in the FrontPage object model. If you are automating FrontPage from another Office application, you should set a reference to the Microsoft FrontPage 4.0 Page Object Reference library by clicking References on the Tools menu in the Visual Basic Editor in the application you are working from. You can then write code to instantiate an Application object variable, as shown in the following example:

Dim fpApp As FrontPage.Application

Set fpApp = New FrontPage.Application

To create a FrontPage Application object without setting a reference to the FrontPage 4.0 Page Object Reference library, you can use the CreateObject function.

If you are writing VBA code from within the FrontPage VBA project, you can refer to the Application object directly without creating an object variable.

From the Application object, you can reach any other object in the FrontPage object model. In addition, the properties, methods, and events of the Application object are also global properties that you can use to return currently active objects. A global property is a property that you can use to return an object without having to refer to the Application object or any top-level objects. The global properties that represent active objects in FrontPage are ActiveDocument, ActivePageWindow, ActiveWeb, and ActiveWebWindow. The following examples illustrate how you can work with these properties and the objects they represent:

' Apply the classic theme to the active document and specify
' vivid colors and active graphics.
ActiveDocument.ApplyTheme "classic", fpThemeVividColors + fpThemeActiveGraphics

' Locate the HelpInformation.htm file in the currently active web.
Dim wflCurrentFile As WebFile

Set wflCurrentFile = ActiveWeb.LocateFile("HelpInformation.htm")
If Not wflCurrentFile Is Nothing Then
   With wflCurrentFile
      ' Code to work with found file here.
   End With
End If

' Check to see if the page in the active page window has changed and, 
' if so, save it to disk.
With ActivePageWindow
   If .IsDirty Then
      .Refresh SaveChanges:=True
   End If
End With

' Display a message showing the window captions for all open 
' documents in the active web window.
Dim pgeCurr          As PageWindow
Dim strCaptions      As String

If ActiveWebWindow.PageWindows.Count > 0 Then
   For Each pgeCurr In ActiveWebWindow.PageWindows
      strCaptions = strCaptions & pgeCurr.Caption & vbCrLf
   Next pgeCurr
   If Len(strCaptions) > 0 Then
      MsgBox "The following pages are currently open:" & vbCrLf & strCaptions
   End If
End If

The Application object also exposes properties that you can use to get information about the current machine, such as the user's name, the version of FrontPage, the language settings, and the registry values, among others. You can use the System property to return the System object, which provides information about the operating system and screen resolution. In addition, you can use the ProfileString property of the System object to read and write FrontPage registry values.

In addition to getting information about the current machine, the Application object provides ten application-level events that you can use to run VBA code when the events occur.