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

Article translations Article translations
Article ID: 257297 - View products that this article applies to.
This article was previously published under Q257297
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

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
          Next
    End 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
       Next
    End Sub
    
    Sub ChangeAllExtensions()
       change_ext ActiveWeb.RootFolder
    End Sub
    					

Properties

Article ID: 257297 - Last Review: October 20, 2013 - Revision: 1.2
APPLIES TO
  • Microsoft FrontPage 2000 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto KB257297

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com