Hi all,
I am not a pro of VBA but I managed to find an awesome code that allows me to insert pictures in column A according to the names written in column B. These pictures are loaded from the same file on the computer.
Here is the code :
The problem is that if I change the images in the root file or if I delete them, Excel does not display them anymore...
I found that with the LinkToFile and SaveWithDocument options, I could change this so that the pictures are definitely linked with the worksheet but I don't know how to properly write the code...
If somebody can help me that would be awesome.
Thank you all !!
I am not a pro of VBA but I managed to find an awesome code that allows me to insert pictures in column A according to the names written in column B. These pictures are loaded from the same file on the computer.
Here is the code :
Code:
Sub Affiche_Image()
Dim Ws As Worksheet ' Sert à manipuler plus facilement l'objet feuille
Dim Image As String ' Contiendra le nom de l'image
Dim Lg As Long ' Numéro de la dernière ligne colonne B
Set Ws = Sheets("Feuil1") ' Nom de la feuille
Application.ScreenUpdating = False ' Interdit le raffraîchissement d'écran
Efface_Images
With Ws
For Lg = 1 To .Range("B65536").End(xlUp).Row ' Parcourt de toute la colonne B
Image = ThisWorkbook.Path & "\CJ\" & .Cells(Lg, "B") ' Répertoire à actualiser
On Error Resume Next ' On s'affranchit des erreurs
With .Pictures.Insert(Image).ShapeRange ' On insère l'image dont le nom est en colonne B
.LockAspectRatio = msoFalse ' On peut la redimmensionner comme on veut
.Left = Ws.Cells(Lg, "A").Left ' Position gauche
.Top = Ws.Cells(Lg, "A").Top ' Position Haut
.Width = Ws.Cells(Lg, "A").Width ' Largeur
.Height = Ws.Cells(Lg, "A").Height ' hauteur
End With
If Err.Number > 0 Then ' Si une erreur (image non présente)
MsgBox .Cells(Lg, "B") & vbCr & "Image inexistante" ' On le signale
End If
Next Lg
End With
End Sub
The problem is that if I change the images in the root file or if I delete them, Excel does not display them anymore...
I found that with the LinkToFile and SaveWithDocument options, I could change this so that the pictures are definitely linked with the worksheet but I don't know how to properly write the code...
If somebody can help me that would be awesome.
Thank you all !!