ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hyperlink (https://www.excelbanter.com/excel-programming/348217-hyperlink.html)

Greg B[_5_]

Hyperlink
 
On my worksheet I want to have hyperlink's to each individual file in a
folder called "cover". Is there a macro that could make this much easier for
me to do?

Thanks

Greg



Ron de Bruin

Hyperlink
 
Hi Gregg

Try this

First macro create a list with file names on the activesheet and the second one create the hyperlinks

Sub test()
Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String

'change to point at the folder to check
myPath = "c:\data"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myFiles) To UBound(myFiles)
Cells(fCtr, 1).Value = myPath & myFiles(fCtr)
Next fCtr
End If
End Sub

Sub test()
Dim mycell As Range
For Each mycell In Columns("A").Cells.SpecialCells(xlCellTypeConstant s)
If mycell.Value < "" Then
ActiveSheet.Hyperlinks.Add Anchor:=mycell, _
Address:=mycell.Value, TextToDisplay:=mycell.Value
End If
Next
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Greg B" wrote in message ...
On my worksheet I want to have hyperlink's to each individual file in a folder called "cover". Is there a macro that could make
this much easier for me to do?

Thanks

Greg





All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com