Event WebPage(aPage As PageWindow) Private m_bRecursive As Boolean Public Property Let Recursive(bValue As Boolean) m_bRecursive = bValue End Property Public Property Get Recursive() As Boolean Recursive = m_bRecursive End Property Public Sub EnumPageWindows() If ActiveWebWindow.Web Is Nothing Then MsgBox "Please open a web before running this macro.", _ vbOKOnly + vbExclamation Exit Sub End If If ActiveWeb.ActiveWebWindow.PageWindows.Count <> 0 Then MsgBox "Please close all files before running this macro.", _ vbOKOnly + vbExclamation Exit Sub End If Dim myTempFolder As WebFolder Set myTempFolder = ActiveWeb.RootFolder GetPages myTempFolder End Sub Private Sub GetPages(myWebFolder As WebFolder) Dim myFiles As WebFiles Dim myFile As WebFile Set myFiles = myWebFolder.Files For Each myFile In myFiles If UCase(myFile.Extension) = "HTM" _ Or UCase(myFile.Extension) = "HTML" Or _ UCase(myFile.Extension) = "ASP" Then myFile.Open Dim myPage As PageWindow Set myPage = ActivePageWindow myPage.ViewMode = fpPageViewNormal RaiseEvent WebPage(myPage) End If Next myFile If m_bRecursive Then Dim mySubFolder As WebFolder For Each mySubFolder In myWebFolder.Folders If mySubFolder.IsWeb = False Then GetPages mySubFolder End If Next mySubFolder End If End Sub Private Sub Class_Initialize() m_bRecursive = True End Sub
This code is in a Class module called SiteScanner. The problem with using RaiseEvent, is that this class must be used from within another class or a form. It is not usable in regular code modules.
Here is a class which shows how to use SiteScanner.
Private WithEvents mySiteScanner As SiteScanner Private Sub mySiteScanner_WebPage(aPage As PageWindow) Dim myString As String myString = aPage.ActiveDocument.Title UserForm1.ListBox1.AddItem myString aPage.Close True End Sub Public Sub GiveMePages() Set mySiteScanner = New SiteScanner mySiteScanner.Recursive = True mySiteScanner.EnumPageWindows End Sub
This code resides in a class module called ScanPages. The processing that you want to do on each file goes in the mySiteScanner_WebPage subroutine. For example you could call the ChangeMenuTitle subroutine that I show above.
You can use this from a code module like this:
Sub GoForIt() Dim myScanner As ScanPages Set myScanner = New ScanPages UserForm1.ListBox1.Clear myScanner.GiveMePages UserForm1.Show End Sub
Comments