LocateFile Method Example

This example locates a file in the root directory of the web and puts the file in edit mode.

Note   You must have a web open and a file called Zinfandel.htm or, you may substitute a file of your choice.

Private Sub LocateAFile()
Dim myFile As WebFile

Set myFile = Webs(0).LocateFile("Zinfandel.htm")
myFile.Edit
End Sub

In most cases, you would probably use the entire URL for the String argument of the LocateFile method. For example, a file may be several levels deep in the folder hierarchy, such as C:/My Documents/My Webs/Rogue Cellars/Inventory/First_Qtr.htm—and you want to locate First_Qtr.htm. Anytime a folder exists in a level deeper than the root directory of the web, use the entire URL as shown in the following example.

Private Sub GetFile()
Dim myFile As String
Dim myFileFound As WebFile

myFile = _
    "C:/My Documents/My Webs/Rogue Cellars/Inventory/First_Qtr.htm"

Set myFileFound = _
    Webs(0).LocateFile(myFile)
End Sub

However, there is a shortcut. For example, if you want to locate a file in an images folder that resides in the root directory of the web, you can use a web relative address by using a forward slash followed by the subfolder and file name as shown in the following statement.

Set myFileFound = _
    Webs(0).LocateFile("images/JPG/myJPGFileList.htm")

Note   You cannot substitute a backslash in a web relative address.