AW: Hyperlinks auswerten und löschen
01.04.2014 08:11:08
fcs
Hallo Chris,
hier ein Makro zum Auslesen und Löschen der Hyperlinks.
Teste es aber erst einmal in einer Kopie des Tabellenblatts.
Ich bin mir nicht sicher, ob ich alle Varanten der Schreibweise der Adressen in den Hyperlinks korrekt erfasst hab.
Gruß
Franz
Sub Hyperlinks_aufloesen()
Dim Zelle As Range, wks As Worksheet
Dim strAdr As String, strPath As String
Dim strOrd As String, AnzOrd As Integer, intPos, intCount As Integer
If MsgBox("Adresse der Hyperlinks in Spalte A in Spalte C eintragen und Hyperlinks löschen?", _
_
vbQuestion + vbOKCancel, "Hyperlinks auflösen") = vbCancel Then Exit Sub
Set wks = ActiveSheet
strPath = ActiveWorkbook.Path
Application.ScreenUpdating = False
With wks
For Each Zelle In .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
With Zelle
If Zelle.Hyperlinks.Count > 0 Then
strAdr = Zelle.Hyperlinks(1).Address
If LCase(Left(strAdr, 4)) = "http" Then
'do nothing - Internet-Link
ElseIf Mid(strAdr, 2, 2) = ":\" Then
'do nothing - Link mit vollständiger Pfadangabe
ElseIf Left(strAdr, 2) = "\\" Then
'do nothing - Link mit Serveradresse - nicht getestet
ElseIf LCase(Left(strAdr, 3)) = "..\" Then
'relative Pfadangabe im Hyperlink
AnzOrd = (Len(strAdr) - Len(VBA.Replace(strAdr, "..\", ""))) / 3
intCount = 0
For intPos = Len(strPath) To 1 Step -1
strOrd = Left(strPath, intPos)
If Mid(strPath, intPos, 1) = "\" Then
intCount = intCount + 1
End If
If intCount = AnzOrd Then Exit For
Next
strAdr = strOrd & VBA.Replace(strAdr, "..\", "")
Else
'Link in Unterverzeichnis des Verzeichnisses der aktiven Datei
strAdr = strPath & "\" & strAdr
End If
Zelle.Offset(0, 2).Value = strAdr
Zelle.Hyperlinks(1).Delete
End If
End With
Next
End With
Application.ScreenUpdating = False
End Sub