Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q257297

↑ Back to the top


Summary

This article demonstrates how to programmatically change file name extensions from .htm to .html in Microsoft Visual Basic for Applications (VBA).

↑ Back to the top


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
    					

↑ Back to the top


Keywords: KB257297, kbhowto

↑ Back to the top

Article Info
Article ID : 257297
Revision : 3
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 218