AW: Zellinhalt per Hyperlink verbinden?
13.04.2021 12:49:23
Nepumuk
Hallo Sergej,
teste mal:
Option Explicit
Public Sub InsertHyperlinks()
Dim astrFolders() As String, strFilename As String
Dim ialngFolders As Long
Dim objCell As Range
astrFolders = GetFolders(ThisWorkbook.Path & "\Auswertungen\")
With Worksheets("Tabelle1") ' Anpassen !!!
For Each objCell In .Range(.Cells(7, 1), .Cells(.Rows.Count, 1).End(xlUp))
If Not IsEmpty(objCell.Value) Then
For ialngFolders = LBound(astrFolders) To UBound(astrFolders)
strFilename = Dir$(astrFolders(ialngFolders) & objCell.Value & "*.*")
If strFilename vbNullString Then
Call .Hyperlinks.Add(Anchor:=objCell, _
Address:=astrFolders(ialngFolders) & strFilename, _
TextToDisplay:=objCell.Value)
Exit For
End If
Next
End If
Next
End With
End Sub
Private Function GetFolders(ByVal pvstrPath As String) As String()
Dim astrFolders() As String
Dim strFolder As String, strPath As String
Dim ialngIndex1 As Long, ialngIndex2 As Long
ReDim Preserve astrFolders(ialngIndex1)
astrFolders(ialngIndex1) = pvstrPath
ialngIndex1 = 1
ialngIndex2 = 1
strPath = pvstrPath
Do
strFolder = Dir$(PathName:=strPath & "*", Attributes:=vbDirectory)
Do Until strFolder = vbNullString
If strFolder "." And strFolder ".." Then
If GetAttr(PathName:=strPath & strFolder) And vbDirectory Then
ReDim Preserve astrFolders(0 To ialngIndex1)
astrFolders(ialngIndex1) = strPath & strFolder & "\"
ialngIndex1 = ialngIndex1 + 1
End If
End If
strFolder = Dir$
Loop
If ialngIndex1 = ialngIndex2 Then Exit Do
strPath = astrFolders(ialngIndex2)
ialngIndex2 = ialngIndex2 + 1
Loop
GetFolders = astrFolders
End Function
Gruß
Nepumuk