Microsoft KB Archive/257297

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

Article ID: 257297

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft FrontPage 2000 Standard Edition

-



This article was previously published under Q257297



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.

 Start Microsoft FrontPage. Open the FrontPage web that you would like to edit. Start the Visual Basic Editor by pressing ALT+F11.  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  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.

 Start Microsoft FrontPage.</li> Open the FrontPage web that you would like to edit.</li> Start the Visual Basic Editor by pressing ALT+F11.</li>  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 </li></ol>

Keywords: kbhowto KB257297

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.