Occurs when a web is closed.
Private Sub Application_OnWebClose(ByVal pWeb As Web, Cancel As Boolean)
pWeb Required WebEx. A WebEx object.
Cancel Required Boolean. True if the closing process was cancelled through the user interface, or if Cancel was set to True. Default is False.
The OnWebClose event is associated with the Application object. When you close a web, the OnWebClose event fires and executes the code that you specified within the event procedure.
This example iterates through the open pages and, if necessary, saves them before the web is closed.
Note To run this example, you must have at least one open web and one open page within that web. This example uses Rogue Cellars as the specified web. You can create a web called Rogue Cellars or substitute a web of your choice.
Create a form called frmLaunchEvents.frm and add two buttons, a button called cmdCloseWeb,
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 cmdCloseWeb_Click section of the code window. This code sample closes the specified web.
Private Sub cmdCloseWeb_Click()
Webs("file:///C:/My Documents/My Webs/Rogue Cellars").Close
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_OnWebClose section of the code window. This code sample iterates through the open pages and saves them if they have been modified.
Private Sub eFPApplication_OnWebClose(ByVal pWeb As Web, _
Cancel As Boolean)
Dim myPageWindows As PageWindows
Dim myPageWindow As PageWindowEx
Set myPageWindows = pWeb.ActiveWebWindow.PageWindows
For Each myPageWindow In myPageWindows
If myPageWindow.IsDirty = True Then myPageWindow.Save
Next
End Sub