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 54
| Private Sub Workbook_Open()
'Insertion photo mosaique
Dim RepertoireImage As String, NomDeLImage As String, ImageLargeur As Single, ShImage As Worksheet
With Sheets("Acceuil")
RepertoireImage = "Photos" ' Ne contient que le nom du répertoire
NomDeLImage = "mosaique repar GP" ' Je dissocie le nom de l'image du chemin complet
End With
Set ShImage = Sheets("Acceuil")
With ShImage
ImageLargeur = .Range("F3:S27").Width ' Pour fixer la largeur de l'image à la largeur de la colonne C
' ImageRatio est une fonction calculant la proportion Largeur / Hauteur pour respecter le format Paysage ou Portrait
Insert_Image2 ShImage, ShImage.Range("F3:S27"), RepertoireImage, NomDeLImage, ImageLargeur, ImageRatio(RepertoireImage & "\" & NomDeLImage)
End With
Set ShImage = Nothing
End Sub
Sub Insert_Image2(ByVal FeuilleImage As Worksheet, ByVal CelluleImage As Range, ByVal RepertoireImages As String, ByVal NomDuFichierImage As String, ByVal LargeurImage As Single, ByVal RatioImage As Single)
'macro complémentaire pour insérer les images
Dim MonImage As Shape
With FeuilleImage
' Suppression de l'image existante
'---------------------------------
' For Each MonImage In .Shapes
' If MonImage.name = "ImageFeuille" Then MonImage.Delete
' Next MonImage
' Insertion de l'image
'---------------------
Set MonImage = .Shapes.AddShape(msoShapeRectangle, CelluleImage.Left, CelluleImage.Top, LargeurImage, LargeurImage / RatioImage)
With MonImage
.name = "mosaique repar GP"
With .Fill
.Visible = msoTrue
.UserPicture "E:\Users\FRANCK\Documents\EXCEL\JOB\réparations\photos\" & "mosaique repar GP.jpg"
End With
With .Line
.Visible = msoTrue
.Weight = 1
End With
End With
Set MonImage = Nothing
End With
End Sub
Function ImageRatio(ByVal CheminEtNomDeLImage As String) As Single
'macro complémentaire pour insérer les images
' A partir du tuto "Utiliser la librairie Windows Image Acquisition en VBA" de SilkyRoad et Bbil
Dim Img As Object
Set Img = CreateObject("WIA.ImageFile")
With Img
.LoadFile "E:\Users\FRANCK\Documents\EXCEL\JOB\réparations\photos\" & "mosaique repar GP.jpg"
ImageRatio = .Width / .Height
End With
Set Img = Nothing
End Function |
Partager