Ajouter du texte image word
v
Bonjour tout le monde,
Je travaille sur un programme Excel qui va automatiquemet créer un rapport selon les données que l'utilisateur met dans l'userform.
J'ai bien réussi à créer le rapport mais il reste un problème au niveau du texte sous l'image
Voici mon code qui s'occupe de créer l'image à une certaine position, mais je n'arrive pas à rajouter la légende pour chaque image
Sub InsertImage()
Dim FolderPath, objFSO, Folder, ImagePath, image, photo, i
Const END_OF_STORY = 6
Const MOVE_SELECTION = 0
FolderPath = Select_Folder_From_Prompt
If InStr(FolderPath, "EMPTY") = 0 Then
Set objFSO = CreateObject("Scripting.Filesystemobject")
Set Folder = objFSO.GetFolder(FolderPath)
For Each image In Folder.Files
ImagePath = image.Path
If CheckiImageExtension(ImagePath) = True Then
'Insert the images into the word document
Set photo = ActiveDocument.Shapes.AddPicture(Filename:=ImagePath, LinkToFile:=False, SaveWithDocument:=True)
With photo
'.LockAspectRatio = msoTrue
.Height = CentimetersToPoints(4.2)
.Width = CentimetersToPoints(16.6)
.RelativeHorizontalPosition = wdRelativeVerticalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = 75
.Top = 100 + i
End With
End If
i = i + 175
ActiveDocument.Shapes("Image 1").Select
Selection.InsertCaption Label:="Figure", TitleAutoText:= _
"InsertionLégende3", Title:="", Position:=wdCaptionPositionBelow, _
ExcludeLabel:=0
Next
End If
'ActiveDocument.Shapes("Image 1").Select
End SubTout en sachant que la variable ImagePath provient d'un sub qui choisit la première image d'un dossier jusqu'à la dernière.
Je crois connaitre le problème, le nom de l'image Picture 1 ou Image 1 n'est pas reconnu.
Merci d'avance à tout le monde