Option Explicit
Sub LancerInsererLimage()
InsererLimage ActiveDocument.Path & "\", ActiveDocument
End Sub
Sub InsererLimage(ByVal CheminImage As String, ByVal WdDoc As Document)
With WdDoc
CheminImage = .Path & "\"
With .Tables(1)
With .Cell(2, 2).Range
CheminImage = CheminImage & Mid(.Text, 1, Len(.Text) - 2) & ".JPG" ' Extension à adapter
End With
If VerifierLeChemin(CheminImage) Then
With .Cell(3, 1).Range ' S'arranger pour que la cellule contienne 1 ligne par défaut
If .InlineShapes.Count > 0 Then .InlineShapes(1).Delete
.InlineShapes.AddPicture FileName:=CheminImage, LinkToFile:=False, SaveWithDocument:=True
With .InlineShapes(1)
.LockAspectRatio = msoTrue
.Height = 200 ' A adapter
End With
.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
Else
MsgBox "Aucune image trouvée !", vbCritical
End If
End With
End With
End Sub
Function VerifierLeChemin(ByVal Chemin2 As String) As Boolean
Dim Fso As Object
VerifierLeChemin = False
Set Fso = CreateObject("Scripting.FileSystemObject")
VerifierLeChemin = Fso.FileExists(Chemin2)
Set Fso = Nothing
End Function