Results 1 to 7 of 7

MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

This is a discussion on MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on. within the Excel Questions forums, part of the Question Forums category; HI I want to search a group of file names in a folder and its sub folders. I need to ...

  1. #1
    New Member
    Join Date
    Dec 2012
    Posts
    7

    Default MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    HI
    I want to search a group of file names in a folder and its sub folders.
    I need to know where they are located and the full name.
    and files searched should be as per format selected.
    Regards

  2. #2
    Board Regular
    Join Date
    Sep 2012
    Location
    Melbourne Australia
    Posts
    1,487

    Default Re: MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    Write a man a macro he is happy for the day....teach a man to write a macro, he'll be happy forever!

  3. #3
    New Member
    Join Date
    Dec 2012
    Posts
    7

    Default Re: MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    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

  4. #4
    New Member
    Join Date
    Dec 2012
    Posts
    7

    Default Re: MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    ..

  5. #5
    Board Regular
    Join Date
    Sep 2012
    Location
    Melbourne Australia
    Posts
    1,487

    Default Re: MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    Write a man a macro he is happy for the day....teach a man to write a macro, he'll be happy forever!

  6. #6
    New Member
    Join Date
    Dec 2012
    Posts
    7

    Default Re: MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    Hi thanks for suggesting file mapping ..
    But here i hav eto extract for a particular set not all the files of particular format.


    I want search a gien set of files each time and its link

  7. #7
    Board Regular
    Join Date
    Sep 2012
    Location
    Melbourne Australia
    Posts
    1,487

    Default Re: MAcro to search multiple files in Folder and its subfolders and extracting their name and locatiey are on.

    The file mapping one show you how to identify all the files in the directory. Idf you only want specific files, either put in an If statement, ignoring any files not on a list, or array, or use the lsit or array to only load specific files.

    file.path and file.name will give you the details you want, you just need to finetune to the information from the mapping to get it to work.
    Last edited by dermie_72; Dec 9th, 2012 at 02:16 PM.
    Write a man a macro he is happy for the day....teach a man to write a macro, he'll be happy forever!

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com