FP2000: How to Loop Through All Files in a Web Using VBAID: Q237672
|
This article explains how to use Visual Basic for Applications to loop through all files in a FrontPage web.
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft Support professionals 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
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspFor more information about using the sample code in this article, please see the following article in the Microsoft Knowledge Base:
Q212536 OFF2000: How to Run Sample Code from Knowledge Base ArticlesThe following code loops through all of the files in the active web and displays the name of each file in a message box.
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
Additional query words:
Keywords : kbdtacode
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 23, 1999