Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
I'm using the following code to insert a file name of an external file into a cell in an Excel spreadsheet, and it works fine. What I would really like to do is make that file name a hyperlink to the file so I can click and open it. I've searched many sites and tried many things but I just can't get it to work for me. Is there anybody out there who can help me please? Thanks for looking at my question. Regards Paul ================================================== =========================== '- SEARCH ALL FILES IN A FOLDER & FIND STRING IN FILE NAME '- PUT NAMES INTO ACTIVE SHEET AT BOTTOM OF COLUMN A '- (search is not case sensitive) '- Brian Baulsom July 2008 '================================================= ============================ Sub FIND_DRAWING() Dim FindText As String Dim MyFolder As String Dim MyFileCount As Integer Dim MyFileName As String Dim MyFileType As String Dim f Dim WS As Worksheet '------------------------------------------------------------------------- '- SET VARIABLES Set WS = ActiveSheet MyFolder = "H:\SERVICE CENTRE DETAILS\INSPECTION DRAWINGS and DOCUMENTS\Misc Drawings" FindText = WS.Range("B2").Value MyFileType = "*" & FindText & "*.*" ' = "*Test*.*" '------------------------------------------------------------------------- '- CHECK FILE NAMES With Application.FileSearch .NewSearch .LookIn = MyFolder .Filename = MyFileType .SearchSubFolders = False ' True to search subfolders '--------------------------------------------------------------------- '- RESULTS MyFileCount = 0 If .Execute() 0 Then MyFileCount = .FoundFiles.Count For f = 1 To MyFileCount MyFileName = .FoundFiles(f) WS.Range("H2").Value = WS.Range("H2").Value & " " & MyFileName Next Else MsgBox ("Search for file names containing : " & FindText & vbCr _ & "No matches found") Exit Sub End If End With '-------------------------------------------------------------------------- '- finish MsgBox ("Found " & MyFileCount & " file names.") End Sub |
#2
![]() |
|||
|
|||
![]()
I believe the line you are looking for to insert after:
WS.Range("H2").Value = WS.Range("H2").Value & " " & MyFileName is: WS.Hyperlinks.Add anchor:=WS.Range("H2"), target:= MyFileName Regards, Mark |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
I tried that but the macro stops at your line and highlights the word 'target' Thanks for your help. Also some drawings have more than 1 sheet, can the code be tweaked to get all the drawings and put them in H2, H3, H4 and so on? Regards paul "BizMark" wrote: I believe the line you are looking for to insert after: WS.Range("H2").Value = WS.Range("H2").Value & " " & MyFileName is: WS.Hyperlinks.Add anchor:=WS.Range("H2"), target:= MyFileName Regards, Mark -- BizMark |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Hyperlink stored in an external workbook | Excel Discussion (Misc queries) | |||
Creating Macro to insert a hyperlink and then sort ... | Excel Discussion (Misc queries) | |||
External hyperlink to a specific page in a workbook | Excel Worksheet Functions | |||
Insert date modified of external file | Excel Discussion (Misc queries) | |||
Intra-workbook hyperlink: macro/function to return to hyperlink ce | Excel Discussion (Misc queries) |