Inserting a Link to a summary


Posted by Alexia on January 03, 2002 7:37 AM

I am writing a macro that will look for all files in a given directory that have been created after a certain date and then extract certain information into the summary.

I want one of the cells to be a link to the file with which that row was updated so that the actual document can be launched from within the summary. Is this possible? If so, any hints on the code would be greatly appreciated. Thanks :-)



Posted by Damon Ostrander on January 03, 2002 9:30 AM

Hi Alexia,

Yes, this is quite easy. See the range object's Hyperlinks collection Add method for adding a hyperlink to a cell. The hyperlink can be either to a file or to a web URL. Here's an example that adds a hyperlink to cell B4 on the Summary worksheet:

With Worksheets("Summary")
.Hyperlinks.Add Anchor:=.[B4], Address:= _
"c:\My Documents\2-D Table Lookup.xls"
End With

You will probably want to change the hard-wired anchor reference (B4) with a computed reference like .Cells(iRow,2) to put the hyperlink in column B in the row defined by the variable iRow, but any type of range reference will do here. Similarly, the hard-wired filename string would be provided by your file name variable.

Happy computing.

Damon