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:
- 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.
- 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