Library tutorials & articles

VBA in FrontPage

Changing every page on my website

I came across Jimco's FrontPage Add-ins and Utilities, and got some ideas from his Remove Underline example which helped me come up with code for looping through all the pages on my site.  Here is the code from that example adapted to my application.

    Sub ChangeAllMenuTitles()
    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
    
    UserForm1.ListBox1.Clear
    ChangeMenu myTempFolder
    UserForm1.Show
    
    MsgBox "Done changing Menu titles.", vbOKOnly + vbInformation
    
End Sub

Sub ChangeMenu(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
            
            ChangeMenuTitle
            
            UserForm1.ListBox1.AddItem ActiveDocument.Title
            myPage.Close True
        End If
        
    Next myFile
    
    Dim mySubFolder As WebFolder
    
    For Each mySubFolder In myWebFolder.Folders
        If mySubFolder.IsWeb = False Then
            ChangeMenu mySubFolder
        End If
    Next mySubFolder
End Sub

  

This code is a little more reusable, but still at the copy and paste level.  Now if I was doing this in C, I would pass a pointer to the function which is used to process each file.  In this case where I have the call to ChangeMenuTitle in the middle of the function, I would call the function using the pointer.  It probably can't be done that way in VBA.

When I was testing an earlier version of of this routine, FrontPage would bog down and hang.  I had another computer, which I borrowed the memory from, to bring my system up to 64 Meg.  After this the routine would run without bogging down the computer.  I was thinking there must be a better way to do this.  What I ended up doing was adding the line "myPage.Close True" to save and close each file after I was done with it.  Now it should run with 32 Meg in the computer.  The 486 was sort of useless even before the Cats chewed off the keyboard cable, so I might as well leave its memory in the Pentium.

Checking to make sure the file is html or asp is important, otherwise you will be opening up all your graphics files.  The first time I ran this without that if statement, I had many PhotoDraw windows appearing.

Comments

  1. 01 May 2007 at 14:07
    Thank you very much for this wonderful effort ... I wish for a long time to find some of this information in any location, but did not find you made pursuant to me very good. You are wonderful. Thanks
     
  2. 01 May 2007 at 14:03
    Thank you very much for this wonderful effort ... I wish for a long time to find some of this information in any location, but did not find you made pursuant to me very good. You are wonderful, Thanks.
  3. 01 Jan 1999 at 00:00

    This thread is for discussions of VBA in FrontPage.

Leave a comment

Sign in or Join us (it's free).

Bill Burris

We'd love to hear what you think! Submit ideas or give us feedback