Try this code
Sub AddLinks()
Dim MyFileName As String
Dim strFolder As String
Dim fso As Object
Dim folder As Variant
Dim RowCount As Long
'file(s) to search for
MyFileName = UserForm1.TextBox2
'directory to start searching
strFolder = UserForm1.TextBox1
RowCount = 3
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(strFolder)
Call GetWorksheetsSubFolder(strFolder + "\", MyFileName, RowCount)
End Sub
Sub GetWorksheetsSubFolder(strFolder As String, MyFileName As String,
RowCount As Long)
Dim fso As Object
Dim folder As Variant
Dim BaseName As String
Dim FName As String
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = _
fso.GetFolder(strFolder)
If folder.subfolders.Count > 0 Then
For Each sf In folder.subfolders
On Error GoTo 100
Call GetWorksheetsSubFolder(strFolder + sf.name + "\",
MyFileName, RowCount)
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
FName = Dir(strFolder & MyFileName)
Do While FName <> ""
BaseName = fso.GetBaseName(FName)
Cells.Hyperlinks.Add _
Anchor:=Range("A" & RowCount), _
Address:=strFolder & FName, _
TextToDisplay:=BaseName
RowCount = RowCount + 1
FName = Dir()
Loop
200 On Error GoTo 0
End Sub
> I would use application.filesearch in a excel macro
> for searching the body text of PDF files, it works with office files but not
[quoted text clipped - 29 lines]
>
> Thank you in advance
Jack - 26 May 2008 09:07 GMT
Thank you for your answer!
I tried the code, but I got an hyperlink to a file I specify in a folder I
specify.
Actually the issue I'm facing is searching for a word in the body text of a
file.
I mean, for instance, searching in a directory all PDF files having the word
"water" in the body text.
The original code I provided works for all office files, but not for PDF.
Maybe I misunderstood how to use your code, in this case please provide some
clarification.
Thank you a lot anyway
Jack
> Try this code
>
[quoted text clipped - 90 lines]
> >
> > Thank you in advance