Solved

Create hyperlink to searchfile result

Posted on 2006-06-11
11
207 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now