Solved

Create hyperlink to searchfile result

Posted on 2006-06-11
11
215 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
[X]
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
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…
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…

710 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