OnBeforeWebPublish Event

       

Occurs before a web is published.

Private Sub Application_OnBeforeWebPublish(ByVal pWeb As Web, Destination As String, Cancel As Boolean)

pWeb   Required WebEx. The specified WebEx object.

Destination   Required String. The URL of the target location.

Cancel   Required Boolean. Causes Microsoft FrontPage to abort the publish when set to True. When Cancel is programmatically set to True, the user can abort the save process by clicking the Cancel button on the form. Default is False.

Remarks

The OnBeforeWebPublish event is associated with the Application object. When the user publishes a web in Microsoft FrontPage, the OnBeforeWebPublish event fires and executes the code that you specified within the event procedure.

Example

This example adds a copyright string to the index page of the web that's being published.

Note   To run this example, you must have at least one open web. This example uses a web called Rogue Cellars. You can create a web called Rogue Cellars or you can substitute a web of your choice in the following code sample.

Create a form called frmLaunchEvents.frm and add two buttons, a button called cmdPublishWeb, and a button called cmdCancel. Add the following code to the Declarations section of a form code window.

Option Explicit
Private WithEvents eFPApplication As Application
Private pPage As PageWindowEx

Add the following code to the UserForm_Initialize section of the code window.

Private Sub UserForm_Initialize()
    Set eFPApplication = New Application
End Sub

Add the following code to the cmdPublishWeb_Click section of the code window.

Private Sub cmdPublishWeb_Click()
    ActiveWeb.Publish "C:\My Documents\My Webs\Rogue Cellars"
End Sub

Add the following code to the cmdCancel_Click section of the code window.

Private Sub cmdCancel_Click()
    'Hide the form.
    frmLaunchEvents.Hide
    Exit Sub
End Sub

Add the following code to the eFPApplication_OnBeforeWebPublish section of the code window.

Private Sub eFPApplication_OnBeforeWebPublish(ByVal pWeb As Web, _
        Destination As String, Cancel As Boolean)
    Dim myCopyright As String
    Dim myIndexFile As WebFile

    myCopyright = "Copyright 1999 by Rogue Cellars"
    Set myIndexFile = pWeb.RootFolder.Files("index.htm")
    myIndexFile.Open
    If myIndexFile.Application.ActiveDocument.body.outerText <> _
            myCopyright Then
        myIndexFile.Application.ActiveDocument.body.insertAdjacentText _
            "BeforeEnd", myCopyright
    End If
    ActivePageWindow.Close
End Sub