FP2000: How to Programmatically Change Files with HTM Extension to HTML

This article was previously published under Q257297
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
This article demonstrates how to programmatically change file name extensions from .htm to .html in Microsoft Visual Basic for Applications (VBA).
MORE INFORMATION
The first method demonstrates how to change the extensions in the root folder only, whereas the second method demonstrates how to change the extensions in both the root folder and subfolders.

Method 1: Root Folder Only

Create a macro that checks each file in the root folder of the web and changes the extension from .htm to .html.
  1. Start Microsoft FrontPage.
  2. Open the FrontPage web that you would like to edit.
  3. Start the Visual Basic Editor by pressing ALT+F11.
  4. In a module sheet, type the following code:
    Sub change_ext()       'Set up variables.   Dim myfiles As Webfiles   Dim myfile As WebFile   Dim fname As String   'Set myfiles equal to the Files collection in the root folder of the    'active web.      Set myfiles = ActiveWeb.RootFolder.Files      'This for loop runs through all of the files in the myfiles       'collection.      For Each myfile In myfiles                'Temporarily store the name of the file.        fname = myfile.Name        'Check to see if the extension is "htm".        If myfile.Extension = "htm" Then        'If the extension is "htm", use the Move method to change it to         '"html".        'When the Move method is used, we can pass parameters to it so that        'links will be updated.            Call myfile.Move(Left(fname, Len(fname) - 3) & "html", True, True)        End If      NextEnd Sub					
  5. Run the macro by pressing F5.

Method 2: Root Folder and Subfolders

Create a macro that checks each file in the root folder and subfolder of the web and changes the extension from .htm to .html.
  1. Start Microsoft FrontPage.
  2. Open the FrontPage web that you would like to edit.
  3. Start the Visual Basic Editor by pressing ALT+F11.
  4. On a module sheet, type the following code:
    Sub change_ext(CurrentFolder As WebFolder)   'Set up variables.   Dim myfiles As WebFiles   Dim myfile As WebFile   Dim fname As String   Dim myfolder As WebFolder   Dim myfolders As WebFolders   'Set myfiles and myfolders equal to the Files collection in the root    'folder and subfolder (respectively) of the active web.   Set myfiles = CurrentFolder.Files   Set myfolders = CurrentFolder.Folders   'This loop runs through all of the files on the myfiles collection.   For Each myfile In myfiles      'Temporarily store the name of the file      fname = myfile.Name      'Check to see if the extension is "htm"      If myfile.Extension = "htm" Then         'If the extension is "htm", use the Move method to change it to          '"html".         'When the Move method is used, we can pass parameters to it so          'that links will be updated.         Call myfile.Move(Left(fname, Len(fname) - 3) & "html", True, True)      End If   Next   'If CurrentFolder has any subfolders then call the subprocedure to    'change the extensions of files within those subfolders.   'Recursion is used below to loop through all folders.  This allows us to    'loop through every file in the web.   'Recursion means that the subprocedure calls itself within itself.   For Each myfolder In myfolders      change_ext myfolder   NextEnd SubSub ChangeAllExtensions()   change_ext ActiveWeb.RootFolderEnd Sub					
Properties

Article ID: 257297 - Last Review: 10/20/2013 18:18:21 - Revision: 1.2

  • Microsoft FrontPage 2000 Standard Edition
  • kbnosurvey kbarchive kbhowto KB257297
Feedback