Dysfonctionnement variable typée
Bonjour à tous,
Encore une question qui me turlupine.
Un type Enum dans une des fonctions que je teste n'est pas pris en compte.
Alez c'est partie pour un test de tout ça.
1er test en Early Binding
Je crée un nouveau projet, je coche la bonne bibliothèque,
Je vérifie que VBE l'a bien prise
Jusque là tout va bien j'ai bien la bibliothèque, et surtout ses constantes ShellSpecialFolderConstants.
Bon c'est parti, insertion d'un module, d'une première fonction, et de sa sub de test.
Public Function GetSpecialFolderPathEB(xFolder As ShellSpecialFolderConstants)
Dim objShell As Shell32.Shell
Dim objFolder As Shell32.Folder
Dim strFullPath As String
Set objShell = New Shell32.Shell
Set objFolder = objShell.Namespace(xFolder)
strFullPath = objFolder.Self.Path
GetSpecialFolderPathEB = strFullPath
End Function
' // Une sub toute bête pour faire les essais
Sub testGetSpecialFolderPath()
MsgBox GetSpecialFolderPathLBEB(ssfDESKTOP)
End Sub
Un petit test renvoie bien le chemin du dossier Bureau
Bon maintenant test en Late Binding
Je décoche la référence, je crée un Type Enum
identique à l'original
Public Enum ShellSpecialFolderConstants
ssfDESKTOP = &H0
ssfPROGRAMS = &H2
ssfCONTROLS = &H3
ssfPRINTERS = &H4
ssfPERSONAL = &H5
ssfFAVORITES = &H6
ssfSTARTUP = &H7
ssfRECENT = &H8
ssfSENDTO = &H9
ssfBITBUCKET = &HA
ssfSTARTMENU = &HB
ssfDESKTOPDIRECTORY = &H10
ssfDRIVES = &H11
ssfNETWORK = &H12
ssfNETHOOD = &H13
ssfFONTS = &H14
ssfTEMPLATES = &H15
ssfCOMMONSTARTMENU = &H16
ssfCOMMONPROGRAMS = &H17
ssfCOMMONSTARTUP = &H18
ssfCOMMONDESKTOPDIR = &H19
ssfAPPDATA = &H1A
ssfPRINTHOOD = &H1B
ssfLOCALAPPDATA = &H1C
ssfALTSTARTUP = &H1D
ssfCOMMONALTSTARTUP = &H1E
ssfCOMMONFAVORITES = &H1F
ssfINTERNETCACHE = &H20
ssfCOOKIES = &H21
ssfHISTORY = &H22
ssfCOMMONAPPDATA = &H23
ssfWINDOWS = &H24
ssfSYSTEM = &H25
ssfPROGRAMFILES = &H26
ssfMYPICTURES = &H27
ssfPROFILE = &H28
ssfSYSTEMx86 = &H29
ssfPROGRAMFILESx86 = &H30
End Enum
Je crée un autre fonction.
Public Function GetSpecialFolderPathLB(xFolder As ShellSpecialFolderConstants)
Dim objShell As Object
Dim objFolder As Object
Dim strFullPath As String
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(xFolder)
strFullPath = objFolder.Self.Path
GetSpecialFolderPathLB = strFullPath
End Function
' // Une sub toute bête pour faire les essais
Sub testGetSpecialFolderPath()
MsgBox GetSpecialFolderPathLB(ssfDESKTOP)
End Sub
Et là pan erreur sur la ligne strFullPath = objFolder.Self.Path
un petit tour au niveau des espions et je m'aperçois que objFolder
et égal à Nothing
Je continue mes investigations, je modifie la Fonction Public Function GetSpecialFolderPathLB(xFolder)
en enlevant la référence au Type Enum et je teste en direct
Sub testGetSpecialFolderPath()
MsgBox GetSpecialFolderPathUB(&H0)
End Sub
Et la ça marche.
Alors problème Excel ou alors suis-je passé à côté de quelque chose......
bonjour,
ça m'a l'air d'être un problème VBA.
si tu enlèves le type dans la définition de ta fonction cela fonctionne (en late binding)
Public Function GetSpecialFolderPathLB(xFolder)
Salut,
Oui je pense, ou alors VBA ne va pas chercher dans la bonne bibliothèque...
Je me pencherais sur le sujet un peu plus tard.