Private Sub CommandButton1_Click()
Dim Choix
With ActiveSheet
Choix = Application.GetOpenFilename("Fichier image(*.gif;*.jpg;*.bmp),*.gif;*.jpg;*.bmp" _
, , "Choix de l'image", , False)
If Choix = False Then Exit Sub
On Error Resume Next
.Shapes("NewPhoto").Delete
Range("A9").Select
.Pictures.Insert(Choix).Name = "NewPhoto"
With .Shapes("NewPhoto")
.IncrementLeft 20.25
.Width = 190
End With
End With
If GetTheFileSize(Choix) > 1000 Then MsgBox "La photo dépasse 1Mo", vbInformation
End Sub
'This Function returns the Filesize in Kb
Public Function GetTheFileSize(ByVal sPath As String) As Long
Dim iChannel As Integer
'Get free channel (file number)
iChannel = FreeFile
'Input file by that channel (file number)
Open sPath For Input As iChannel
'Return file size
GetTheFileSize = Format((LOF(iChannel) / 1024), "#.0")
End Function