Option Explicit
Public sQR As String '--- pour conserver valeur code avant sa modification
Sub QR_LigneActive()
QRCODE ActiveCell.Row
End Sub
Sub QRCODE(kr As Long)
Dim T As Variant, oldCell As Range
Dim sID As String, sLink As String, sPict As Object
' retenir la cellule active avant changement
Set oldCell = ActiveCell
With ActiveSheet
' S'il y a moins de 5 valeur alors on sort
If Application.CountA(.Cells(kr, 1).Resize(, 5)) < 5 Then Exit Sub
'
' Tableau des valeurs
T = Application.Transpose(Application.Transpose(.Cells(kr, 1).Resize(, 5).Value))
'
' Concatener les valeur avec un point-virgule
sID = Join(T, ";") '--- 2 = colonne où se trouve le texte à traiter
'
' la ligne suivante ne devrait plus servir
If sID = "" Or sID = ";;;;" Then Exit Sub '=== EXIT SUB ===
sID = VCard
sID = Replace(sID, "[Nom]", .Cells(kr, "A").Text)
sID = Replace(sID, "[Prenom]", .Cells(kr, "B").Text)
sID = Replace(sID, "[Fonction]", .Cells(kr, "C").Text)
sID = Replace(sID, "[Mobile]", .Cells(kr, "D").Text)
sID = Replace(sID, "[email]", .Cells(kr, "E").Text)
'
' Supprimer le QR_code s'il existe déjà
SupprimerQR "QR_" & .Cells(kr, 1) & "_" & .Cells(kr, 2)
sLink = "https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=" & AssainirURL(sID)
Debug.Print sLink
.Cells(kr, 6).Activate
Set sPict = .Pictures.Insert(sLink)
With sPict
.Name = "QR_" & Cells(kr, 1) & "_" & Cells(kr, 2)
'--- change la taille
.Width = 60
.Height = 60
'--- change la position
.Left = Cells(kr, "F").Left + 30
.Top = Cells(kr, "F").Top
'--- pour info
Debug.Print .Name & " ajouté", , .Left, .Top
End With
oldCell.Activate
.Cells(kr, 1).RowHeight = 66
Set sPict = Nothing
End With
End Sub
Function VCard() As String
VCard = "BEGIN:VCARD" & vbCrLf & _
"VERSION:4.0" & vbCrLf & _
"FN:[Prenom] [Nom]" & vbCrLf & _
"N:[Nom];[Prenom]" & vbCrLf & _
"ROLE:[Fonction]" & vbCrLf & _
"TEL;CELL:[Mobile]" & vbCrLf & _
"EMAIL;INTERNET:[email]" & vbCrLf & _
"UID:" & vbCrLf & _
"END:VCARD"
End Function
Sub ListerShapes()
Dim shape As Excel.shape
For Each shape In ActiveSheet.Shapes
Debug.Print shape.ID, shape.Name
Next
End Sub
Sub SupprimerQR(sCode As String)
'--- supprime image ayant le même nom,
'--- mais ne supprime pas image qui se trouverait à la même place avec un autre nom
'--- chose qui se produit lorsque l'on change le texte du code dans la cellule
'--- => utiliser Worksheet_SelectionChange() pour détecter le code avant modification
Dim shape As Excel.shape
For Each shape In ActiveSheet.Shapes
If shape.Name = sCode Then
Debug.Print sCode & " supprimé ID:"; shape.ID
shape.Delete
End If
Next
End Sub
Function AssainirURL(MonURL As String)
'par Excel-Malin.com ( https://excel-malin.com )
On Error GoTo FonctionErreur
Dim URLtemporaire As String
URLtemporaire = MonURL
URLtemporaire = Replace(URLtemporaire, "%", "%25")
URLtemporaire = Replace(URLtemporaire, Chr(10), "%0A")
URLtemporaire = Replace(URLtemporaire, Chr(13), "%0D")
URLtemporaire = Replace(URLtemporaire, ":", "%3A")
URLtemporaire = Replace(URLtemporaire, " ", "%20")
URLtemporaire = Replace(URLtemporaire, """", "%22")
URLtemporaire = Replace(URLtemporaire, "#", "%23")
URLtemporaire = Replace(URLtemporaire, "$", "%24")
URLtemporaire = Replace(URLtemporaire, "&", "%26")
URLtemporaire = Replace(URLtemporaire, "'", "°%27")
URLtemporaire = Replace(URLtemporaire, "(", "%28")
URLtemporaire = Replace(URLtemporaire, ")", "%29")
URLtemporaire = Replace(URLtemporaire, "*", "%2A")
URLtemporaire = Replace(URLtemporaire, "+", "%2B")
URLtemporaire = Replace(URLtemporaire, ",", "%2C")
URLtemporaire = Replace(URLtemporaire, ";", "%3B")
URLtemporaire = Replace(URLtemporaire, "<", "%3C")
URLtemporaire = Replace(URLtemporaire, "=", "%3D")
URLtemporaire = Replace(URLtemporaire, ">", "%3E")
URLtemporaire = Replace(URLtemporaire, "?", "%3F")
URLtemporaire = Replace(URLtemporaire, "@", "%40")
URLtemporaire = Replace(URLtemporaire, "[", "%5B")
URLtemporaire = Replace(URLtemporaire, "]", "%5D")
URLtemporaire = Replace(URLtemporaire, "^", "%5E")
URLtemporaire = Replace(URLtemporaire, "`", "%60")
URLtemporaire = Replace(URLtemporaire, "{", "%7B")
URLtemporaire = Replace(URLtemporaire, "|", "%7C")
URLtemporaire = Replace(URLtemporaire, "}", "%7D")
URLtemporaire = Replace(URLtemporaire, "~", "%7E")
URLtemporaire = Replace(URLtemporaire, "¢", "%C2%A2")
URLtemporaire = Replace(URLtemporaire, "£", "%C2%A3")
URLtemporaire = Replace(URLtemporaire, "¥", "%C2%A5")
URLtemporaire = Replace(URLtemporaire, "|", "%A6")
URLtemporaire = Replace(URLtemporaire, "§", "%C2%A7")
URLtemporaire = Replace(URLtemporaire, "«", "%C2%AB")
URLtemporaire = Replace(URLtemporaire, "¬", "%C2%AC")
URLtemporaire = Replace(URLtemporaire, "¯", "%C2%AF")
URLtemporaire = Replace(URLtemporaire, "º", "%C2%BA")
URLtemporaire = Replace(URLtemporaire, "±", "%C2%B1")
URLtemporaire = Replace(URLtemporaire, "ª", "%C2%AA")
URLtemporaire = Replace(URLtemporaire, ",", "%B4")
URLtemporaire = Replace(URLtemporaire, "µ", "%C2%B5")
URLtemporaire = Replace(URLtemporaire, "»", "%C2%BB")
URLtemporaire = Replace(URLtemporaire, "¼", "%C2%BC")
URLtemporaire = Replace(URLtemporaire, "½", "%C2%BD")
URLtemporaire = Replace(URLtemporaire, "¿", "%C2%BF")
URLtemporaire = Replace(URLtemporaire, "À", "%C3%80")
URLtemporaire = Replace(URLtemporaire, "Á", "%C3%81")
URLtemporaire = Replace(URLtemporaire, "Â", "%C3%82")
URLtemporaire = Replace(URLtemporaire, "Ã", "%C3%83")
URLtemporaire = Replace(URLtemporaire, "Ä", "%C3%84")
URLtemporaire = Replace(URLtemporaire, "Å", "%C3%85")
URLtemporaire = Replace(URLtemporaire, "Æ", "%C3%86")
URLtemporaire = Replace(URLtemporaire, "Ç", "%C3%87")
URLtemporaire = Replace(URLtemporaire, "È", "%C3%88")
URLtemporaire = Replace(URLtemporaire, "É", "%C3%89")
URLtemporaire = Replace(URLtemporaire, "Ê", "%C3%8A")
URLtemporaire = Replace(URLtemporaire, "Ë", "%C3%8B")
URLtemporaire = Replace(URLtemporaire, "Ì", "%C3%8C")
URLtemporaire = Replace(URLtemporaire, "Í", "%C3%8D")
URLtemporaire = Replace(URLtemporaire, "Î", "%C3%8E")
URLtemporaire = Replace(URLtemporaire, "Ï", "%C3%8F")
URLtemporaire = Replace(URLtemporaire, "Ð", "%C3%90")
URLtemporaire = Replace(URLtemporaire, "Ñ", "%C3%91")
URLtemporaire = Replace(URLtemporaire, "Ò", "%C3%92")
URLtemporaire = Replace(URLtemporaire, "Ó", "%C3%93")
URLtemporaire = Replace(URLtemporaire, "Ô", "%C3%94")
URLtemporaire = Replace(URLtemporaire, "Õ", "%C3%95")
URLtemporaire = Replace(URLtemporaire, "Ö", "%C3%96")
URLtemporaire = Replace(URLtemporaire, "Ø", "%C3%98")
URLtemporaire = Replace(URLtemporaire, "Ù", "%C3%99")
URLtemporaire = Replace(URLtemporaire, "Ú", "%C3%9A")
URLtemporaire = Replace(URLtemporaire, "Û", "%C3%9B")
URLtemporaire = Replace(URLtemporaire, "Ü", "%C3%9C")
URLtemporaire = Replace(URLtemporaire, "Ý", "%C3%9D")
URLtemporaire = Replace(URLtemporaire, "Þ", "%C3%9E")
URLtemporaire = Replace(URLtemporaire, "ß", "%C3%9F")
URLtemporaire = Replace(URLtemporaire, "à", "%C3%A0")
URLtemporaire = Replace(URLtemporaire, "á", "%C3%A1")
URLtemporaire = Replace(URLtemporaire, "â", "%C3%A2")
URLtemporaire = Replace(URLtemporaire, "ã", "%C3%A3")
URLtemporaire = Replace(URLtemporaire, "ä", "%C3%A4")
URLtemporaire = Replace(URLtemporaire, "å", "%C3%A5")
URLtemporaire = Replace(URLtemporaire, "æ", "%C3%A6")
URLtemporaire = Replace(URLtemporaire, "ç", "%C3%A7")
URLtemporaire = Replace(URLtemporaire, "è", "%C3%A8")
URLtemporaire = Replace(URLtemporaire, "é", "%C3%A9")
URLtemporaire = Replace(URLtemporaire, "ê", "%C3%AA")
URLtemporaire = Replace(URLtemporaire, "ë", "%C3%AB")
URLtemporaire = Replace(URLtemporaire, "ì", "%C3%AC")
URLtemporaire = Replace(URLtemporaire, "í", "%C3%AD")
URLtemporaire = Replace(URLtemporaire, "î", "%C3%AE")
URLtemporaire = Replace(URLtemporaire, "ï", "%C3%AF")
URLtemporaire = Replace(URLtemporaire, "ð", "%C3%B0")
URLtemporaire = Replace(URLtemporaire, "ñ", "%C3%B1")
URLtemporaire = Replace(URLtemporaire, "ò", "%C3%B2")
URLtemporaire = Replace(URLtemporaire, "ó", "%C3%B3")
URLtemporaire = Replace(URLtemporaire, "ô", "%C3%B4")
URLtemporaire = Replace(URLtemporaire, "õ", "%C3%B5")
URLtemporaire = Replace(URLtemporaire, "ö", "%C3%B6")
URLtemporaire = Replace(URLtemporaire, "÷", "%C3%B7")
URLtemporaire = Replace(URLtemporaire, "ø", "%C3%B8")
URLtemporaire = Replace(URLtemporaire, "ù", "%C3%B9")
URLtemporaire = Replace(URLtemporaire, "ú", "%C3%BA")
URLtemporaire = Replace(URLtemporaire, "û", "%C3%BB")
URLtemporaire = Replace(URLtemporaire, "ü", "%C3%BC")
URLtemporaire = Replace(URLtemporaire, "ý", "%C3%BD")
URLtemporaire = Replace(URLtemporaire, "þ", "%C3%BE")
URLtemporaire = Replace(URLtemporaire, "ÿ", "%C3%BF")
AssainirURL = URLtemporaire
Exit Function
FonctionErreur:
AssainirURL = CVErr(xlErrValue)
End Function