Re salu Cerber, le Forum
Je ne sais pas ce que tu cherches à faire, mais voici un exemple avec un appel API et une fonction qui va retourner la version de Windows (c'est pas de moi, mais c'est pour faire un exemple concrèt)... En fonction de çà, la variable "Chemin" sera initialisée avec une des trois constantes en top de module... C'est juste à titre d'exemple, car il faudrait aussi retourner le User ID car "UserName" est évidemment faux.
Option Explicit
Const WinNT As String = "C:\WinNt\Profiles\UserName\Personal\"
Const Win2K As String = "C:\Documents and Settings\UserName\My Documents\"
Const Win9x As String = "C:\My Documents\"
Public lpVersionInformation As OSVERSIONINFO
Private Declare Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Long
'de Zeloran Stronghold, adapté VBA par Patrick Penet
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Public Function OperatingSystem() As Integer
lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
Call GetVersionExA(lpVersionInformation)
If (lpVersionInformation.dwPlatformId = 0) Then
OperatingSystem = 0
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 0) Then OperatingSystem = 1
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 10) Then OperatingSystem = 2
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 90) Then OperatingSystem = 3
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion < 5) Then OperatingSystem = 4
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion = 5) And _
(lpVersionInformation.dwMinorVersion = 0) Then OperatingSystem = 5
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion = 5) And _
(lpVersionInformation.dwMinorVersion = 1) Then OperatingSystem = 6
End If
End Function
Sub ShowWVersion()
Dim OS As String, a As String, Chemin As String
a = OperatingSystem
Select Case a
Case 0: OS = "Windows 32": MsgBox "Ouh Là Là !!": Exit Sub
Case 1: OS = "Windows 95": Chemin = Win9x
Case 2: OS = "Windows 98": Chemin = Win9x
Case 3: OS = "Windows ME": Chemin = Win9x
Case 4: OS = "Windows NT": Chemin = WinNT
Case 5: OS = "Windows 2000": Chemin = Win2K
Case 6: OS = "Windows XP": Chemin = Win2K
End Select
MsgBox "Votre Opérating Système est :" & OS & vbCrLf & _
"le chemin d'accès de vos documents devrait être : " & vbCrLf _
& Chemin
End Sub
Voilà, Cerber c'est peut-être pas du tout ce dont tu as besoin, mais c'est un exemple d'initialisation de Chemin d'une manière variable.
Ensuite pour "OpenFile" (Open tout seul, car "OpenFile" n'existe pas) tu peux faire comme ceci :
Sub Cerber ()
Dim Chemin As String
Dim Fichier As String
Chemin = "C:\Mes Documents\" '(qui donc pourrait être initialisé avec des conditions)
Fichier = "TOTO.xls"
Workbooks.Open Chemin & Fichier
End Sub
Voilà c'est pas vraiment compliqué.
Bon Après Midi
@+Thierry