Begins the search for the specified file(s). Returns a Long; zero (0) if no files are found, or a positive number if one or more files are found.
expression.Execute(SortBy, SortOrder, AlwaysAccurate)
expression Required. An expression that returns a FileSearch object.
SortBy Optional MsoSortBy. The method used to sort the returned file(s).
MsoSortBy can be one of these MsoSortBy constants. |
msoSortByFileName default |
msoSortByFileType |
msoSortByLastModified |
msoSortByNone |
msoSortBySize |
SortOrder Optional MsoSortOrder. The order in which the returned file(s) are sorted.
MsoSortOrder can be one of these MsoSortOrder constants. |
msoSortOrderAscending default |
msoSortOrderDescending |
AlwaysAccurate Optional Boolean. True to have the file search include files that have been added, modified, or deleted since the file index was last updated. The default value is True.
For the command bar objects, runs the procedure or built-in command assigned to the specified command bar control. For custom controls, use the OnAction property to specify the procedure to be run.
For FileDialog objects of type msoFileDialogOpen or msoFileDialogSaveAs, carries out a user's action right after the Show method is invoked.
expression.Execute
expression Required. An expression that returns one of the above objects.
Example
As it applies to the FileSearch object.
This example searches for all files in the My Documents folder that end with the file name extension “.doc” and then displays the location and name of each file found. The example also sorts the list of returned file names in ascending alphabetic order.
Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "*.doc"
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
This Microsoft Excel example creates a command bar and then adds a built-in command bar button control to it. The button executes the Excel AutoSum function. This example uses the Execute method to total the selected range of cells when the command bar appears.
Dim cbrCustBar As CommandBar
Dim ctlAutoSum As CommandBarButton
Set cbrCustBar = CommandBars.Add("Custom")
Set ctlAutoSum = cbrCustBar.Controls _
.Add(msoControlButton, CommandBars("Standard") _
.Controls("AutoSum").Id)
cbrCustBar.Visible = True
ctlAutoSum.Execute