Microsoft KB Archive/238410

= FP2000: How to Change Capitalization of File and Folder Names Using VBA =

PSS ID Number: 238410

Article Last Modified on 8/30/2002

-

The information in this article applies to:


 * Microsoft FrontPage 2000
 * Microsoft Visual Basic for Applications

-



This article was previously published under Q238410



SUMMARY
The sample code in this article changes the capitalization of the file and folder names in the active Web to lowercase.



MORE INFORMATION
To run this macro, insert the code into a module in the Visual Basic Editor and run the MyProcedure macro.

NOTE: This code should not be run on discussion webs

Sub MyProcedure 'Set up a variable to hold the result of a message box Dim myMessageResults As VbMsgBoxResult '/////////////////////////////////////////////////////////////////    'A web must be open for this macro to work. To check to see if a   'web is open, we check the Caption property of the FrontPage 'application. If a web is open, the caption will read '"Microsoft FrontPage - ". If no web is open, the 'caption will only read "Microsoft FrontPage". '/////////////////////////////////////////////////////////////////

'Check the caption of the application to see if a web is open. If Application.ActiveWebWindow.Caption = "Microsoft FrontPage" Then

'If no web is open, display a message box. MsgBox "Please open a web before running this macro.", _ vbOKOnly + vbExclamation

'. . . and end the macro. Exit Sub

End If   '////////////////////////////////////////////////////////////////// 'In order for us to update the HTML in our files, there must be no   'pages open. To check for this, we check the Count property of   'the PageWindows collection. The PageWindows collection's Count 'property is equal to the number of files that are currently open. '//////////////////////////////////////////////////////////////////

'Get the count of the PageWindows collection If ActiveWeb.ActiveWebWindow.PageWindows.Count <> 0 Then

'Assign the result of a message box to the variable myMessageResults = _ MsgBox("Please close all files before running this macro.", _         vbOKOnly + vbExclamation)

'If the user clicks OK in our message box, exit the macro. 'This variable will equal vbOK as soon as the user clicks 'the OK button in the message box. If myMessageResults = vbOK Then Exit Sub

End If

'Set up a variable for the WebFolder we're passing to the 'ChangeCase procedure Dim myTmpWebFolder As WebFolder 'Set the myWebFolder variable to equal the rootfolder of  'the active web Set myTmpWebFolder = ActiveWeb.RootFolder 'Now call the ChangeCase procedure and pass myWebFolder to it. ChangeCase myTmpWebFolder 'Display a dialog saying we're done. myMessageResults = MsgBox _ ("Conversion to lower case completed.", vbOKOnly + vbInformation) End Sub

Sub ChangeCase(myWebFolder As WebFolder) 'Set up all variables Dim myWebFiles As WebFiles Dim myWebFile As WebFile Dim myWebFolders As WebFolders Dim myFile As String 'Set myWebFiles equal to the active web's Files collection Set myWebFiles = myWebFolder.Files

'Set myWebFolders equal to the active web's Folders collection Set myWebFolders = myWebFolder.Folders 'This For loop loops through each file in the root folder For Each myWebFile In myWebFiles

'Assign the name of the active file to myFile myFile = myWebFile.Name

'/////////////////////////////////////////////////////////////////        'We use the Move method to rename the files and folders. When 'we use the Move method to rename files, it doesn't actually 'change the HTML links. Therefore, we first rename the file 'to "tempname" and then rename it to the lower case equivalent 'of its original name. This forces FrontPage to update the HTML. '/////////////////////////////////////////////////////////////////

'Rename the file to its temporary name Call myWebFile.Move("tempname", True, True)

'Now we rename the file to the lower case equivalent of       'its original name. Call myWebFile.Move(LCase(myFile), True, True)

Next myWebFile '//////////////////////////////////////////////    '//  Loop through the subfolders '//////////////////////////////////////////////    'Set up a variable for the folder Dim myLoopFolder As WebFolder 'This For loop loops through each folder that is a subfolder 'off of the root folder. For Each myLoopFolder In myWebFolders

'/////////////////////////////////////////////////////////////////        'When we use the Move method to rename the folders, FrontPage 'will update the HTML links automatically. Therefore, we don't       'need to rename the folders to a temporary name first as we did 'with the files. '/////////////////////////////////////////////////////////////////

'Check to make sure that the folder is not a subweb. If it's not, 'go ahead and change the case on it. 'We use MakeRel so that the folder retains its current 'relative URL. If myLoopFolder.IsWeb = False Then _ Call myLoopFolder.Move(LCase(MakeRel _ (ActiveWeb, myLoopFolder.Url)), True, True)

Next myLoopFolder 'Since folder names may have changed, we need to refresh the 'web so we see everything ActiveWeb.Refresh 'Now we have to recursively call the ChangeCase procedure so   'that we can loop through all folders in the web. Dim mySubFolder As WebFolder For Each mySubFolder In myWebFolder.Folders 'Only call ChangeCase if the current subfolder is not a subweb If mySubFolder.IsWeb = False Then ChangeCase mySubFolder Next mySubFolder

End Sub

The capitalization can be changed to all uppercase for file and folder names by replacing all instances of the LCase method with UCase.

For example, your code will look similar to the following for changing the capitalization to all lowercase: Call myWebFile.Move(LCase(myFile), True, True) To change it to all uppercase, replace LCase with UCase in your code: Call myWebFile.Move(UCase(myFile), True, True)

