+ Reply to Thread
Results 1 to 11 of 11

How do you search a folder for a cell item " NAME", then return a hyperlink if found?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-05-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    52

    How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    Hello all,

    I am looking for a way to have my spread sheet search a folder with PDFs based on an item name in a call like "CO DETECTORS" IF another cell I have has a "TRUE" in it, and if the name is listed on the PDF file name return a hyperlink to that PDF file.

    Can this be done?

    example:
    IF cell D1 is "TRUE"
    Search for file name of cell D2 "CO DETECTORS" in a folder on my hard drive "C:\Users\user\Pictures\MP Navigator EX\2012_05_30"
    and if file name found give cell D3 "HYPERLINK" to that file!

    Thanks to all that take the time to look at this question, Jerry.

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    try this:

    Sub hyperlink_add()
    Dim MyFile As String
    If Range("D1").Value = True Then
        MyFile = "C:\Users\user\Pictures\MP Navigator EX\2012_05_30\" & Range("D2").Value
        If Dir(MyFile) <> "" Then
            Range("D3").Hyperlinks.Add anchor:=Range("D3"), Address:=MyFile
        End If
    End If
    End Sub

  3. #3
    Registered User
    Join Date
    05-05-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    Thanks NickyC, I adjusted the code to work with my needs.

    Two things I can't seem to work out,

    1: The Macro only works after I unlock the work book SHEET 3 "MATERIAL LIST", Although locked would be best so others do not change formulas Accidently.

    2: Can the code be made to work on all rows? of SHEET 3 "MATERIAL LIST" (7:4019) What I tried made a big mess!!!!

    I have attached a simple version of the spread sheet we use for our non profit company.

    Thanks again for all who take the time to help.

    Below is the code I have now.

    Sub hyperlink_add()
    Dim MyFile As String
    If Range("F7").Value = "WX" Then
        MyFile = "C:\Users\user\Pictures\MP Navigator EX\2012_05_30\" & Range("B7").Value & ".pdf"
        If Dir(MyFile) <> "" Then
            Range("H7").Hyperlinks.Add anchor:=Range("H7"), Address:=MyFile
        End If
    End If
    End Sub
    Attached Files Attached Files
    Last edited by NicksDad; 06-01-2012 at 02:28 PM.

  4. #4
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    will you interrogate all of the cells in column F separately, or do you want to find links to all the filenames in column B if only F7 is checked?
    assuming the former, try this:


    Sub hyperlink_add2()
    Dim rng, cc As Range, MyFile As String
    rng = Range("A7:F3338").Address ' enter range to interrogate here
    For Each cc In Range(rng).Columns("F").Cells
        If cc.Value = "WX" Then
            MyFile = "C:\Users\user\Pictures\MP Navigator EX\2012_05_30\" & cc.Offset(0, -4).Value & ".pdf"
            If Dir(MyFile) <> "" Then Range("H7").Hyperlinks.Add anchor:=Range("H7"), Address:=MyFile
        End If
    Next cc
    End Sub

  5. #5
    Registered User
    Join Date
    05-05-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    Thanks again for getting back to me NickyC,

    I would like to interrogate all of the cells in column F separately.
    I need to treat each row separately with its own hyperlink to the column B name PDF of its row, IF column F for that row has "WX" checked.

    example: If "WX" Checked in column F of row 100 then return Hyperlink in column H of row 100 to the name in column B in row 100.
    If "WX" not checked in column F of row 100 then no hyperlink in column H of row 100.

    The same should be true of each row independent of each of the other rows.

    I hope this helps.

  6. #6
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    hi the macro above should achieve that

  7. #7
    Registered User
    Join Date
    05-05-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    Hi NickyC,
    The macro works GREAT on row 7, but not on any of the other rows in column H. If any of the other rows column F has "WX" checked the hyperlink shows up on row 7 column H only.

    I wish I could see how to make this macro work to add a hyperlink on each row (H7:H4019)of the column H cells independent of all other rows.

    With my limited knowledge of VBA, the only way I know to change the ("H7") range is ("H7:H4019")and that did notwork, Sorry for my lack of code skills!
    And Thanks for all the time you have put in to this....

    Sub hyperlink_add2()
    Dim rng, cc As Range, MyFile As String
    rng = Range("A7:F4019").Address ' enter range to interrogate here
    For Each cc In Range(rng).Columns("F").Cells
        If cc.Value = "WX" Then
            MyFile = "C:\Users\user\Documents\Invoices\" & cc.Offset(0, -4).Value & ".pdf"
            If Dir(MyFile) <> "" Then Range("H7").Hyperlinks.Add anchor:=Range("H7"), Address:=MyFile
        End If
    Next cc
    End Sub
    Last edited by NicksDad; 06-04-2012 at 06:13 PM.

  8. #8
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    ah - sorry; try this:

    Sub hyperlink_add2()
    Dim rng, cc As Range, MyFile As String
    rng = Range("A7:F4019").Address ' enter range to interrogate here
    For Each cc In Range(rng).Columns("F").Cells
        If cc.Value = "WX" Then
            MyFile = "C:\Users\user\Documents\Invoices\" & cc.Offset(0, -4).Value & ".pdf"
            If Dir(MyFile) <> "" Then cc.Offset(0, 2).Hyperlinks.Add anchor:=cc.Offset(0, 2), Address:=MyFile
        End If
    Next cc
    End Sub

  9. #9
    Registered User
    Join Date
    05-05-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    You are the BEST!! Works like a charm, What can I do for you?

    You have saved me hours and hours.

  10. #10
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    no worries - glad to help

  11. #11
    Registered User
    Join Date
    05-05-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: How do you search a folder for a cell item " NAME", then return a hyperlink if found?

    NickyC, I can't Thank you enough, you are a VBA god!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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