OnBeforeWebPublish Event 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 PageWindow

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)
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