J'ai pu implémenter le code fourni par l'exemple de LouReed. C'est OK mais je dois afficher des images de taille différente. Or, largeur et hauteur sont en constante dans la macro. Je voudrais pouvoir aller chercher les caractéristique de l'image avant et ainsi calculer un ratio correct afin que l'image ne soit pas déformée.
Si quelqu'un peut m'aider, ce serait super!
Option Explicit
Const deltaX = 10 ' horizontal
Const deltaY = 20 ' vertical
Const offsetX = 0
Const offsetY = 0
Function MonImage( _
ByVal url As String, _
ByVal repertoire As String, _
ByVal fichier As String, _
Optional ByVal largeur As Long = 600, _
Optional ByVal hauteur As Long = 150, _
Optional ByVal texte As String = "") As Variant
Application.Volatile
Dim oImg As Shape, oRng As Range, oLargImage As Integer, oHautImage As Integer
Dim iPict As IPictureDisp
oLargImage = 513 / 2
oHautImage = 600 / 2
Set oRng = Application.Caller.Offset(offsetY, offsetX)
On Error Resume Next
Set oImg = oRng.Parent.Shapes(Application.Caller.Address)
oImg.Delete
On Error GoTo 0
If url = "" Then GoTo fin
On Error GoTo fin
Set oImg = oRng.Parent.Shapes.AddPicture(url, msoFalse, msoTrue, oRng.Left + deltaX, oRng.Top + deltaY, largeur, hauteur)
oImg.Name = Application.Caller.Address
MonImage = texte
Exit Function
fin:
MonImage = "pas d'image"
End Function