Solved

Create hyperlink to searchfile result

Posted on 2006-06-11
11
212 Views
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
0
Comment
Question by:brigham
  • 4
  • 2
11 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 500 total points
ID: 16882463
Hi,

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) & ")"


BFN,

fp.
0
 

Author Comment

by:brigham
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
0
 

Author Comment

by:brigham
ID: 16891261
The "FoundFiles" object gave me the path and file extension.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16916842
Hi,

Do you need any further assistance?

BFN,

fp.
0
 
LVL 35

Expert Comment

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

Expert Comment

by:DanRollins
ID: 17322661
fanpages,
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
0
 
LVL 35

Expert Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now