Sid
Private Function FileExists(fname) As Boolean
' Returns TRUE if the file exists
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True _
Else FileExists = False
End Function
IF(fileexists(C:\path\image x.jpg),(HYPERLINK(C:\path\image x.jpg)),"")
Sub InsertHyperlinks()
Dim i As Long, LastRow As Long
Dim StrTemp As String
LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If FileExists(Sheets("Sheet1").Range("A" & i).Value) Then
StrTemp = Sheets("Sheet1").Range("A" & i).Value
Sheets("Sheet1").Hyperlinks.Add Anchor:=Range("A" & i), Address:=StrTemp, _
TextToDisplay:=StrTemp
End If
Next i
End Sub
Private Function FileExists(fname) As Boolean
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True
End Function
Inserting-Hyperlinks.xls
Sub InsertHyperlinks()
Dim i As Long, j As Long, LastRow As Long
Dim StrTemp As String
LastRow = Sheets("Sheet1").Range("G" & Rows.Count).End(xlUp).Row
lastcol = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To LastRow
For j = 7 To lastcol
StrTemp = Sheets("Sheet1").Cells(i, j).Value
If FileExists(StrTemp) Then
Sheets("Sheet1").Hyperlinks.Add Anchor:=Sheets("Sheet1").Cells(i, j - 6), Address:=StrTemp, _
TextToDisplay:=StrTemp
Else
Sheets("Sheet1").Cells(i, j - 6).ClearContents
End If
Next j
Next i
End Sub
Public Function FileExists(fname) As Boolean
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True
End Function
Private Sub Workbook_Open()
Dim i As Long, j As Long, LastRow As Long
Dim StrTemp As String
LastRow = Sheets("Sheet1").Range("G" & Rows.Count).End(xlUp).Row
lastcol = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To LastRow
For j = 7 To lastcol
StrTemp = Sheets("Sheet1").Cells(i, j).Value
If FileExists(StrTemp) Then
Sheets("Sheet1").Hyperlinks.Add Anchor:=Sheets("Sheet1").Cells(i, j - 6), Address:=StrTemp, _
TextToDisplay:=StrTemp
Else
Sheets("Sheet1").Cells(i, j - 6).ClearContents
End If
Next j
Next i
End Sub
Public Function FileExists(fname) As Boolean
Dim x As String
x = Dir(fname)
If x <> "" Then FileExists = True
End Function
my-insert-hyperlink-sample-file-.xlsmJoin the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
16 Experts available now in Live!