Ed,
thanks for your advice/
I use the following code in MS Office 2003/SP-2/WinXP SP-2:
Sub Moltest()
' Moltest Macro
' Macro created 02.08.2006 by IA
'Dim x, y, z As String, MyName As String
Dim i As Integer
Dim Response As Integer, TotalFiles As Integer
On Error Resume Next
Folder:
' Prompt the user for the folder to list.
X = InputBox(Prompt:="What folder do you want to list?" & vbCr & vbCr _
& "For example: C:\My Documents", _
Default:="G:\Docart")
y = InputBox(Prompt:="What files do you want to look for?" & vbCr & vbCr _
& "For example: *.doc", _
Default:="*.doc; *.htm; *.txt")
Z = InputBox(Prompt:="Insert keywords" & vbCr & vbCr _
& "For example: Reactor And nuclear")
If X = "" Or X = " " Or y = "" Or y = " " Or Z = "" Or Z = " " Then
If MsgBox("Either you did not type a text correctly" _
& vbCr & "or you clicked Cancel. Do you want to quit?" _
& vbCr & vbCr & _
"If you want to type once more, click No." & vbCr & _
"If you want to quit, click Yes.", vbYesNo) = vbYes Then
Exit Sub
Else
GoTo Folder
End If
End If
' Test if folder exists.
If Dir(X, vbDirectory) = "" Then
MsgBox "The folder does not exist. Please try again."
GoTo Folder
End If
' Search the specified folder for files
' and type the listing in the document.
With Application.FileSearch
.NewSearch
.FileType = y
' Change the .FileType to the type of files you are looking for;
' for example, the following line finds all files:
' .FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.FileName = ""
.MatchTextExactly = False
.TextOrProperty = Z
.LookIn = X
.Execute
TotalFiles = .FoundFiles.Count
If TotalFiles = 0 Then
MsgBox ("There are no files in the folder!" & _
"Please type another folder to list.")
GoTo Folder
End If
' Create a new document for the file listing.
Application.Documents.Add
ActiveDocument.ActiveWindow.View = wdPrintView
' Set tabs.
With Selection.ParagraphFormat.TabStops
.Add _
Position:=InchesToPoints(3), _
Alignment:=wdAlignTabLeft, _
Leader:=wdTabLeaderSpaces
.Add _
Position:=InchesToPoints(4), _
Alignment:=wdAlignTabLeft, _
Leader:=wdTabLeaderSpaces
End With
' Type the file list headings.
Selection.TypeText "File Listing of the "
With Selection.Font
.AllCaps = True
.Bold = True
End With
Selection.TypeText X
With Selection.Font
.AllCaps = False
.Bold = False
End With
Selection.TypeText " folder!" & vbLf
Selection.Font.Underline = wdUnderlineSingle
Selection.TypeText vbLf & "File Name" & vbTab & "File Size" _
& vbTab & "File Date/Time" & vbLf & vbLf
Selection.Font.Underline = wdUnderlineNone
For i = 1 To TotalFiles
MyName = .FoundFiles(i)
Selection.TypeText MyName & vbTab & FileLen(MyName) _
& vbTab & FileDateTime(MyName) & vbLf
Next i
' Type the total number of files found.
Selection.TypeText vbLf & "Total files in folder = " & TotalFiles & _
" files."
End With
MsgBox ("The number of files is " & TotalFiles & _
" files.")
If MsgBox("Do you want to list another folder?", vbYesNo) = vbYes Then
GoTo Folder2
Else
GoTo Konets1
End If
Folder2:
Konets1:
End Sub
If I use the first keyword, it is about 1000 files in TotalFiles, with
second it become 3000 and with third - 6000.
It looks like instead of AND code uses OR function, and I do not realize,
why it happens
Petr.