1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| 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 sID As String, sLink As String, sPict As Object
With ActiveSheet
sID = .Cells(kr, 2) '--- 2 = colonne où se trouve le texte à traiter
If sID = "" Then Exit Sub '=== EXIT SUB ===
SupprimerQR "QR_" & sID
sLink = "http://chart.googleapis.com/chart?cht=qr&chs=145x135&chl=" & sID
.Cells(kr, 3).Activate
Set sPict = .Pictures.Insert(sLink)
With sPict
.Name = "QR_" & sID
'--- change la taille
.Width = 60
.Height = 60
'--- change la position
.Left = .Left + 5
.Top = .Top + 5
'--- pour info
Debug.Print .Name & " ajouté", , .Left, .Top
End With
.Cells(kr + 1, 2).Activate
Set sPict = Nothing
End With
End Sub
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 |
Partager