Hello Everyone,
I'm pretty new to macros and I have this code that works wonderfully except for it will not let me add a second value to search with. Below is the particular section of the code I’m having issues with -
Dim fs As FileSearch
Set fs = Application.FileSearch
fs.NewSearch
With fs
With .PropertyTests
.Add _
Name:="Text or Property", _
Condition:=msoConditionIncludesPhrase, _
Value:=tiger And tigertwo
', _SecondValue:=tigertwo
I want it to have 2 values – tiger and tigertwo
When I put - Value:=tiger And tigertwo it says Run-time Error “13”: type mismatch.
When I put - Value:=tiger
,_SecondValue:=tigertwo it finds everything with both types of variables instead of docs with both variables in it.
*** it is looking thru text files ***
For example Below each number represents a report being searched thru. The words in the report on the respective line
1. fish
2. chips
3. fish horse chips
4. horse
5. fish chips
6. chips fish horse
7. horse chips fish
8. apples chip
9. horse fish
I would like the macro to only return reports 3, 5, 6,7
My entire code is below –
Sub EJG ()
Sheets.Add After:=ActiveSheet
Cells(2, 1) = "T N"
Cells(2, 2) = "l 4 C #"
Cells(2, 3) = "T#"
Cells(2, 5) = "S D"
Cells(2, 6) = "E D"
Columns("A:F").AutoFit
UserForm1.Show
ttt3:
If Range("E1") > Range("F1") Then
MsgBox "Your Start Date is Later Than Your End Date"
UserForm1.Show
GoTo ttt3
End If
'*******************************
'*******************************
'*******************************
myrow = 3
tiger = Cells(1, 2).Text
tigertwo = Cells(1, 3).Text
datefield = Cells(1, 1).Text
datest = Cells(1, 5)
origstdate = Cells(1, 5)
dateend = Cells(1, 6)
'*******************************
'*******************************
'*******************************
'*******************************
loc1:
Cells(1, 5) = datest
Cells(1, 5).NumberFormat = "mmddyyyy"
datesttx = Cells(1, 5).Text
Dim fs As FileSearch
Set fs = Application.FileSearch
fs.NewSearch
With fs
With .PropertyTests
.Add _
Name:="Text or Property", _
Condition:=msoConditionIncludesPhrase, _
Value:=tiger And tigertwo
', _SecondValue:=tigertwo
End With
.LookIn = "D:\" & datesttx
.SearchSubFolders = True
.FileName = "*" & datefield & "*.*"
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
End With
If fs.Execute() > 0 Then
'MsgBox "There were " & fs.FoundFiles.Count & " file(s) found."
For i = 1 To fs.FoundFiles.Count
Cells(myrow, 1) = fs.FoundFiles(i)
Cells(myrow, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=fs.FoundFiles(i), _
TextToDisplay:=fs.FoundFiles(i)
myrow = myrow + 1
Next i
If datest < dateend + 1 Then
datest = DateAdd("d", 1, datest)
GoTo loc1
End If
Else
If datest < dateend + 1 Then
datest = DateAdd("d", 1, datest)
GoTo loc1
End If
If Cells(3, 1) = vbNullString Then
MsgBox "There were no files found."
End If
End If
Cells(1, 5).NumberFormat = "m/d/yyyy"
Cells(1, 5) = origstdate
End Sub
Please help!
Thank you very, very much in advance!!!
Bookmarks