Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Range(Target.Address).Hyperlinks.Count > 0 Then
' Comment récupérer le texte d'un lien hypertext ?
' Colone 1 = Target.Value
' Colonne 2 = Target.Offset(0, 1).Value
Target.Offset(0, 1).Value = Trim(Split(Target.Hyperlinks.Item(1).Address, "\")((UBound(Split(Target.Hyperlinks.Item(1).Address, "\")))))
'Liste pour remmplacer
Target.Offset(0, 1).Value = Replace(Target.Offset(0, 1).Value, "%20", " ")
Target.Offset(0, 1).Value = Replace(Target.Offset(0, 1).Value, "é", "é")
Target.Offset(0, 1).Value = Replace(Target.Offset(0, 1).Value, "ê", "ê")
' REGEX (Fonction de conversion)
Target.Offset(0, 1).Value = URLDecode(Target.Offset(0, 1).Value) ' Target.Offset(0, 1).Value = sStr
End If
End Sub
'
'
' Fonction ci-dessous
Function RegExTest(str, patrn)
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
regEx.IgnoreCase = True
regEx.Pattern = patrn
RegExTest = regEx.test(str)
End Function
'
Function URLDecode(sStr)
' https://newbedev.com/decoding-url-encoded-utf-8-strings-in-vbscript
' Décodage de chaînes UTF-8 codées url dans VBScript
Dim str, code, a0
str = ""
code = sStr
code = Replace(code, "+", " ")
While Len(code) > 0
If InStr(code, "%") > 0 Then
str = str & Mid(code, 1, InStr(code, "%") - 1)
code = Mid(code, InStr(code, "%"))
a0 = UCase(Mid(code, 2, 1))
If a0 = "U" And RegExTest(code, "^%u[0-9A-F]{4}") Then
str = str & ChrW((Int("&H" & Mid(code, 3, 4))))
code = Mid(code, 7)
ElseIf a0 = "E" And RegExTest(code, "^(%[0-9A-F]{2}){3}") Then
str = str & ChrW((Int("&H" & Mid(code, 2, 2)) And 15) * 4096 + (Int("&H" & Mid(code, 5, 2)) And 63) * 64 + (Int("&H" & Mid(code, 8, 2)) And 63))
code = Mid(code, 10)
ElseIf a0 >= "C" And a0 <= "D" And RegExTest(code, "^(%[0-9A-F]{2}){2}") Then
str = str & ChrW((Int("&H" & Mid(code, 2, 2)) And 3) * 64 + (Int("&H" & Mid(code, 5, 2)) And 63))
code = Mid(code, 7)
ElseIf (a0 <= "B" Or a0 = "F") And RegExTest(code, "^%[0-9A-F]{2}") Then
str = str & Chr(Int("&H" & Mid(code, 2, 2)))
code = Mid(code, 4)
Else
str = str & "%"
code = Mid(code, 2)
End If
Else
str = str & code
code = ""
End If
Wend
URLDecode = str
End Function