Solved

Create hyperlink to searchfile result

Posted on 2006-06-11
11
209 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

910 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

25 Experts available now in Live!

Get 1:1 Help Now