0

As a learning exercise and to do something productive, I decided to write a VBA macro for one of my "very old" FrontPage websites. Actually I'm in the process of trying to escape from FrontPage(FP)...

This seemingly simple project, I am familiar with VBA for Excel and Access, was to open a series of current web pages in FP and save them to a different folder so I could begin to remove all of the FP stuff without affecting the working parts of the website.

I Google-ed "FrontPage" and "VBA" extensively but there seems to be a dearth of useful information out there. Any references I did find pointed to pages/sites that are no longer active. So I muddled along with what information I did find and this is the result:

Sub OpenAndSaveAsPages()
Dim objPageWindow As PageWindowEx
Dim objFileOpen As FileDialog
Dim strFolder As String
Dim strFile As Variant
Dim intCount As Integer
Dim strURL As String
'File Open dialog object.
Set objFileOpen = FrontPage.Application.FileDialog(msoFileDialogOpen)
'startup folder default is the root folder of the active Web site
strFolder = ActiveWeb.RootFolder
' clean up unwanted stuff in the URL
strFolder = Replace(strFolder, "file:///", "")
strFolder = Replace(strFolder, "/", "\")
objFileOpen.InitialFileName = strFolder
If objFileOpen.Show < 0 Then
    For Each strFile In objFileOpen.SelectedItems
' Open web file in FP
        ActiveWebWindow.PageWindows.Add strFile
' at this point all I wanted to do was a SAVEAS to save the file to a different folder
' so I wanted to do something like below but could not figure it out
'           objPageWindow.SaveAs objPageWindow.Document.Url
    Next
End If
' Now all the selected file are open in FrontPage and I will iterate through them
For Each objPageWindow In ActiveWebWindow.PageWindows
' the URL for the currently select page
    strURL = objPageWindow.Document.Url
' probably some extra work here to change the URL to a different folder and filename
    strURL = Replace(strURL, Mid(strURL, InStrRev(strURL, ".", Len(strURL)), Len(strURL) + 1 - InStrRev(strURL, ".", Len(strURL))), Mid(strURL, InStrRev(strURL, ".", Len(strURL)), Len(strURL) + 1 - InStrRev(strURL, ".", Len(strURL))), 1)
    strURL = Replace(strURL, Left(strURL, InStrRev(strURL, "/", Len(strURL))), Left(strURL, InStrRev(strURL, "/", Len(strURL))) & "temp/", 1)
    objPageWindow.SaveAs strURL
    objPageWindow.Close
Next
End Sub

OK, it works but for sure it is probably not the most efficient and for sure not elegant.

So, my questions are:

  1. are there and good references for FP VBA that you can recommend (I'm not a professional programmer, just someone that like to ...). I work well in using examples to achieve and learn.
  2. Can someone sharpen up my code, with explanations, of course.

Note, I'm not trying to write any code to actually modify the code in these pages. I may get to that, but for now it appears that a "SAVEAS" results in code which is already fairly clean of the FP stuff.

Many thanks....RDK

RDK
  • 355
  • 2
  • 7
  • 24
  • 1
    While certainly a _learning exercise_, this will not lead to _something productive_, not even some fun, only frustrations, as FrontPage is not only ancient but also totally outdated as it has been left in the dark for two decades; it is for a reason, that you have a hard time finding useful code. So, pick some newer technology and allocate your precious time to _convert_ those old FrontPage sites. – Gustav Dec 15 '22 at 15:34
  • If you're looking for help optimizing your code, there is a sub stack called [Code Review](https://codereview.stackexchange.com/) . – Cameron Critchlow Dec 15 '22 at 16:11
  • 1
    @Gustav Yes, it has not been fun getting this far, but I'm stubborn. I have several FP sites which I have been looking at to move simple HTML or PHP. I have looked at the "native" FP code and there are several modifications I have tried to clean things up. But the " and " tags do not remove cleanly, ie they leave some unmatched tags. What I have discovered is that if I open the page in FP (or Expression Web 4) and do a SAVEAS that the resulting code is clean of the above tags. And when run through an HTLM editor that there are no longer the hanging tags. – RDK Dec 15 '22 at 16:30
  • So, while not fun and yes frustrating, I think I'm on a path which will allow me to more easily update/convert this FP web. I have a couple XL VBA macros which I'm also using to fix up the format, the includes and JavaScript oddities. – RDK Dec 15 '22 at 16:33

0 Answers0