hi
this is what was shared here only in one of the forums
this gives the hyperlink to all the files in the directory.
I need it to be selective.
like if i have to search some files
say:
aa
bb
cc
dd
ee
ff
gg
hh
in a directory it should search it and give me the hypertext
Sub HyperlinksToDirectory()
Dim stDir As String
Dim stFile As String
Dim colFiles As New Collection
Dim R As Range
Set R = ActiveCell
stDir = InputBox("Directory?", , Default:=CurDir())
'stFile = Dir(stDir & "\*.*")
RecursiveDir colFiles, stDir, "*.doc*", True
Dim vFile As Variant
For Each vFile In colFiles
R.Hyperlinks.Add R, vFile, , , vFile
Set R = R.Offset(1)
Next vFile
R.CurrentRegion.Sort key1:=R, order1:=xlAscending, Header:=xlNo
End Sub
Public Function RecursiveDir(colFiles As Collection, _
strFolder As String, _
strFileSpec As String, _
bIncludeSubfolders As Boolean)
Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant
'Add files in strFolder matching strFileSpec to colFiles
strFolder = TrailingSlash(strFolder)
strTemp = Dir(strFolder & strFileSpec)
Do While strTemp <> vbNullString
colFiles.Add strFolder & strTemp
strTemp = Dir
Loop
If bIncludeSubfolders Then
'Fill colFolders with list of subdirectories of strFolder
strTemp = Dir(strFolder, vbDirectory)
Do While strTemp <> vbNullString
If (strTemp <> ".") And (strTemp <> "..") Then
If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then
colFolders.Add strTemp
End If
End If
strTemp = Dir
Loop
'Call RecursiveDir for each subfolder in colFolders
For Each vFolderName In colFolders
Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True)
Next vFolderName
End If
End Function
Public Function TrailingSlash(strFolder As String) As String
If Len(strFolder) > 0 Then
If Right(strFolder, 1) = "\" Then
TrailingSlash = strFolder
Else
TrailingSlash = strFolder & "\"
End If
End If
End Function
urgently need it
thanks