Create hyperlink to searchfile result

Posted on 2006-06-11
Last Modified: 2010-04-30
I have an excel spreadsheet with over 7000 names of image files (TIF and JPG) on our server contributed by scientists around the world.  I would like to write a VBA macro to hyperlink the file name on the Excel worksheet "index" to the files.  All of the files are in the same directory, but scattered into many subfolders.  I have written a "searchfile" macro to that takes the content of the Excel cell and finds the appropriate file.  The problem is that there is a variable file path and the files have different extensions (mostly TIF and JPG).  Any suggestions would be greatly appreciated. thanks, Brigham
Question by:brigham
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 35

Accepted Solution

[ fanpages ] earned 500 total points
ID: 16882463

In your VBA, you can use the syntax:

<Worksheet>.Hyperlinks.Add Anchor:=<cell>, Address:="c:\filename.jpg", TextToDisplay:="Click to open filename.jpg"

e.g. to create a link on sheet [index] in cell B2:

Worksheets("index").Hyperlinks.Add Anchor:=[B2], Address="c:\my folder\file.tif", TextToDisplay:="Open TIF"

Or an in-cell formula of:

=HYPERLINK("c:\", "Click to open folder view of C:\")

That can be converted to VBA, thus:

<cell>.Formula = "=HYPERLINK(" & Chr$(34) & "c:\" & Chr$(34) & "," & Chr$(34) & "Click to open folder view of C:\" & Chr$(34) & ")"

Range("B2").Formula = "=HYPERLINK(" & Chr$(34) & "c:\" & Chr$(34) & "," & Chr$(34) & "Click to open folder view of C:\" & Chr$(34) & ")"



Author Comment

ID: 16884472
Thanks for your comments.  I'm still stuck on how to point to the results of FileSearch.  You refer to "c:\my folder\file.tif" but in my case, I'm searching for the file.  I'm confident of the name, but not the path or the file extension (TIF or JPG).  For example,

Set fs = Application.FileSearch
With fs
     .LookIn = "D:\Images"
     .SearchSubFolders = True
     .FileName = MyFile
End With

FileSearch finds the file, but does it provide an address for the hyperlink?  Thanks, b

Author Comment

ID: 16891261
The "FoundFiles" object gave me the path and file extension.
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

LVL 35

Expert Comment

by:[ fanpages ]
ID: 16916842

Do you need any further assistance?


LVL 35

Expert Comment

by:[ fanpages ]
ID: 17322177
Thank you once again.
LVL 49

Expert Comment

ID: 17322661
While I appreciate the thanks, please be aware that whenever there is a comment posted after the recommendation, it takes the Moderator a few extra keystrokes to finalize the Q.  Again, I appreciate the gesture, but if you don't have an objection to the recommendation, it is slightly better for the Cleanup Crew if you don't post.  I'm fine with assuming that you have thanked me in your heart :-)
-- Dan
LVL 35

Expert Comment

by:[ fanpages ]
ID: 17322848
OK, noted Dan, thank you... and apologies for this (final) comment :)

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question