Private Sub Workbook_Open()
NomPhoto = Dir(repertoire & "*.jpg")
Call LoadPict
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Feuil1.Image1.Picture = Nothing
ActiveWorkbook.Save
End Sub
Sub OnOff()
If flag Then
flag = False
NomPhoto = Dir(repertoire & "*.jpg")
Call LoadPict
Exit Sub
End If
flag = True
ActiveSheet.Image1.Picture = Nothing
Call auto_close
Do
If flag Then Exit Do
DoEvents
Loop
End Sub
'C'est le chemin des images
Public Const repertoire As String = "D:\Dossiers Excel\The Best Of VBA\Diaporama sur Feuille\"
Public NomPhoto
Public temps
Public flag As Boolean
Sub LoadPict()
On Error GoTo fin
Feuil1.Image1.Picture = LoadPicture(repertoire & NomPhoto)
NomPhoto = Dir
If NomPhoto = "" Then NomPhoto = Dir(repertoire & "*.jpg")
temps = Now + TimeValue("00:00:03")
Application.OnTime temps, "LoadPict"
fin:
Exit Sub
End Sub
Sub auto_close()
On Error Resume Next
Application.OnTime temps, Procedure:="LoadPict", Schedule:=False
End Sub