FP2000: How to Loop Through All Files in a Web Using VBA (237672)



The information in this article applies to:

  • Microsoft FrontPage 2000

This article was previously published under Q237672

SUMMARY

This article explains how to use Visual Basic for Applications to loop through all files in a FrontPage web.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

The following code loops through all of the files in the active web and displays the name of each file in a message box.

To use this code, copy it into a module in the Visual Basic Editor in FrontPage 2000 and run the MyProcedure macro.

Sub MyProcedure()
    'Call the PrintName function.  We pass the root folder of the
    'active web to the PrintName function as a WebFolder object.
    PrintName ActiveWeb.RootFolder
End Sub

Function PrintName(myFolder As WebFolder) As Boolean

    'Set up the variables.
    Dim myFile As WebFile
    Dim mySubFolder As WebFolder

    'This For loop loops through the all of the files in the folder
    'represented by the myFolder variable.
    For Each myFile In myFolder.Files
        'Display the name of the current file in a message box.
        MsgBox myFile.Name
    Next myFile

    'Recursion is used below to loop through all folders.
    'This allows us to loop through every file in the web.
    'Recursion means that the function calls itself from
    'within itself.
    
    'This For loop loops through all of the folders in the web.
    'It calls the PrintName function each time and passes the current
    'folder name.  This allows us to assign the folder represented by 
    'the myFolder variable.
    For Each mySubFolder In myFolder.Folders
        'Call the PrintName function and pass the current subfolder 
        'as a WebFolder object.  
        PrintName mySubFolder
    Next mySubFolder

    'Assign value of True to PrintName
    PrintName = True    

    'A function must return a value.  The PrintName function returns
    'a boolean value.

    'Code can be added to a macro to check the value of PrintName.
    'If the value of PrintName is True, it indicates that this function
    'completed successfully.
    
End Function

				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto kbProgramming KB237672