+ Reply to Thread
Results 1 to 2 of 2

Search xls files in directory for String and return Hyperlink

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    Glen Carbon, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    8

    Search xls files in directory for String and return Hyperlink

    Hey all im willing to learn whatever just point me in the right direction :-)

    What im needing to do is search a specific directory full of .XLS files and return hyperlink(s) to all files that contain the Search String... Example

    Column A1 - A100 has search words
    Column B1 - B100 Returns a Hyperlink(s) to all files within directory that contain that word.

    I saw some Marcos on here that will search but how would you get the marco to output to a specific Cell?

    Any questions or anything i left out that you need let me know thanks alot!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Search xls files in directory for String and return Hyperlink

    SATEAT,

    The following macro will create hyperlinks to the intended files
    Notes:
    -Change the FldrLoc to the path of the folder that contains the files
    • Make sure to include the ending slash \
    Sub testpart()
    
        Dim FldrLoc As String:      FldrLoc = "C:\Test Folder\Test Subfolder\"
        Dim rngCriteria As Range:   Set rngCriteria = ActiveSheet.Range("A1:A100")
        
        Dim CurrentFile As String, iCell As Range, rngAnchor As Range
        For Each iCell In rngCriteria
            If IsEmpty(iCell) = False Then
                CurrentFile = Dir(FldrLoc)
                Do While CurrentFile <> vbNullString
                    If InStr(1, CurrentFile, iCell.Value, vbTextCompare) > 1 Then
                        
                        Set rngAnchor = ActiveSheet.Cells(iCell.Row, Columns.Count).End(xlToLeft).Offset(0, 1)
                        ActiveSheet.Hyperlinks.Add _
                            Anchor:=rngAnchor, _
                            Address:=FldrLoc & CurrentFile, _
                            TextToDisplay:=CurrentFile
                        
                    End If
                    CurrentFile = Dir()
                Loop
            End If
        Next iCell
        
    
    End Sub


    Hope that helps,
    ~tigeravatar

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1