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.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay