Private Sub CommandButton2_Click()
Dim fichier As Variant, img As Picture
On Error Resume Next
ActiveSheet.Shapes("img").Delete
Err.Clear
fichier = Application.GetOpenFilename("Text Files (*.jpg), *.jpg", 1, "ouvrir un fichier")
If fichier = False Then Exit Sub
Set img = ActiveSheet.Pictures.Insert(fichier)
img.Name = "img"
place_l_image_dans2 [C5], img, Val(GetImg_Orientation(fichier))
End Sub
Sub place_l_image_dans2(Rng As Range, Shp As Picture, Optional rot As Long = 0)
Dim x As Boolean, leftmoins&, topmoins&
Application.ScreenUpdating = False
With Shp
.ShapeRange.LockAspectRatio = msoTrue ' met l'aspect Ratio a true
If rot = 0 Then
If Shp.Height > Rng.Height Then Shp.Height = Rng.Height
If Shp.Width > Rng.Width Then Shp.Width = Rng.Width
Else
Shp.ShapeRange.Rotation = rot:
If Shp.Width > Rng.Height Then Shp.Width = Rng.Height
If Shp.Height > Rng.Width Then Shp.Height = Rng.Width
leftmoins = Abs(.Width - .Height) / 2
topmoins = Abs(.Height - .Width) / 2
End If
.Left = (Rng.Left - leftmoins)
.Top = (Rng.Top + topmoins)
End With
End Sub
Private Function GetImg_Orientation(fichier) As Long
Dim Dossier, img, Fld, Fich
Dossier = Mid(fichier, 1, InStrRev(fichier, "\") - 1)
img = Mid(fichier, InStrRev(fichier, "\") + 1)
Set shApp = CreateObject("Shell.Application")
Set Fld = shApp.Namespace(Dossier)
Set Fich = Fld.items.Item(img)
GetImg_Orientation = -Val(Replace(Replace(Fld.getdetailsof(Fich, 245), "Pivoter de ", ""), " degrés", ""))
End Function