在发布站点之前发生。
Private Sub Application_OnBeforeWebPublish(ByVal pWeb As Web, Destination As String, Cancel As Boolean)
pWeb 必选,WebEx 类型。指定的 WebEx 对象。
Destination 必选,String 类型。目标位置的 URL。
Cancel 必选,Boolean 类型。设置成 True 时会使 Microsoft FrontPage 放弃发布。当利用编程方式将 Cancel 设置为 True 时,用户可以通过单击表单上的“取消”按钮来放弃保存过程。默认值为 False。
OnBeforeWebPublish 事件与 Application 对象相关联。当用户在 Microsoft FrontPage 中发布站点时,OnBeforeWebPublish 事件会触发并且执行事件过程中指定的代码。
本示例向要发布站点的索引网页添加一个版权所有字符串。
注意 若要运行本示例,必须至少打开一个站点。本示例使用一个称为 Rogue Cellars 的站点。您可以创建一个称为 Rogue Cellars 的站点,或在下列代码示例中用您所选择的站点来代替。
创建一个称为 frmLaunchEvents.frm 的表单并添加两个按钮,分别称为 cmdPublishWeb
和 cmdCancel
。将下列代码添加到表单代码窗口的 Declarations 部分。
Option Explicit
Private WithEvents eFPApplication As Application
Private pPage As PageWindowEx
将下列代码添加到代码窗口的 UserForm_Initialize 部分。
Private Sub UserForm_Initialize()
Set eFPApplication = New Application
End Sub
将下列代码添加到代码窗口的 cmdPublishWeb_Click 部分。
Private Sub cmdPublishWeb_Click()
ActiveWeb.Publish "C:\My Documents\My Webs\Rogue Cellars"
End Sub
将下列代码添加到代码窗口的 cmdCancel_Click 部分。
Private Sub cmdCancel_Click()
'Hide the form.
frmLaunchEvents.Hide
Exit Sub
End Sub
将下列代码添加到代码窗口的 eFPApplication_OnBeforeWebPublish 部分。
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