IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Valeurs par défaut de Microsoft Windows


Sujet :

Macros et VBA Excel

  1. #1
    Membre habitué
    Homme Profil pro
    Inscrit en
    Juin 2006
    Messages
    622
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 622
    Points : 156
    Points
    156
    Par défaut Valeurs par défaut de Microsoft Windows
    Bonjour à tous,

    Ici on peut voir toutes les valeurs Windows par défaut :

    http://en.wikipedia.org/wiki/Environment_variable

    Comment les utiliser en VBA pour accéder à un fichier ?
    (en fait je réalise une macro qui devra pouvoir s'éxécuter sur différents systèmes et multilangues).

    Par exemples pour %programfiles%

    Prenons un exemple simple : le lancement de Internet Explorer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    RetVal = Shell("C:\Program Files\Internet Explorer\iexplore.exe"
    Comment faire de même en utilisant les variables Windows ?

    Merci

    A+
    Dams'

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    752
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 752
    Points : 832
    Points
    832
    Par défaut
    Petit recherche dans la FAQ, ça donne ça:
    http://access.developpez.com/faq/?pa...em#RecupVarEnr

    J'espère que c'est bien ce que tu recherches.

  3. #3
    Membre éprouvé
    Avatar de fred65200
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    901
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 901
    Points : 1 207
    Points
    1 207
    Par défaut chemins spéciaux
    bonjour, peut être que ce que te sera utile.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
     Option Explicit
     
     
     ' déclaration Api
     Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
     Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
     
     Type SHITEMID
     cb As Long
     abID As Byte
     End Type
     
     Type ITEMIDLIST
     mkid As SHITEMID
     End Type
     
     'Constantes
     Global Const NOERROR = 0
     Global Const CSIDL_DESKTOP = &H0 '{desktop}
     Global Const CSIDL_INTERNET = &H1 'Internet Explorer (icon on desktop)
     Global Const CSIDL_PROGRAMS = &H2 'Start Menu\Programs
     Global Const CSIDL_CONTROLS = &H3 'My Computer\Control Panel
     Global Const CSIDL_PRINTERS = &H4 'My Computer\Printers
     Global Const CSIDL_PERSONAL = &H5 'My Documents
     Global Const CSIDL_FAVORITES = &H6 '{user}\Favourites
     Global Const CSIDL_STARTUP = &H7 'Start Menu\Programs\Startup
     Global Const CSIDL_RECENT = &H8 '{user}\Recent
     Global Const CSIDL_SENDTO = &H9 '{user}\SendTo
     Global Const CSIDL_BITBUCKET = &HA '{desktop}\Recycle Bin
     Global Const CSIDL_STARTMENU = &HB '{user}\Start Menu
     Global Const CSIDL_DESKTOPDIRECTORY = &H10 '{user}\Desktop
     Global Const CSIDL_DRIVES = &H11 'My Computer
     Global Const CSIDL_NETWORK = &H12 'Network Neighbourhood
     Global Const CSIDL_NETHOOD = &H13 '{user}\nethood
     Global Const CSIDL_FONTS = &H14 'windows\fonts
     Global Const CSIDL_TEMPLATES = &H15
     Global Const CSIDL_COMMON_STARTMENU = &H16 'All Users\Start Menu
     Global Const CSIDL_COMMON_PROGRAMS = &H17 'All Users\Programs
     Global Const CSIDL_COMMON_STARTUP = &H18 'All Users\Startup
     Global Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19 'All Users\Desktop
     Global Const CSIDL_APPDATA = &H1A '{user}\Application Data
     Global Const CSIDL_PRINTHOOD = &H1B '{user}\PrintHood
     Global Const CSIDL_LOCAL_APPDATA = &H1C '{user}\Local Settings _
     '\Application Data (non roaming)
     Global Const CSIDL_ALTSTARTUP = &H1D 'non localized startup
     Global Const CSIDL_COMMON_ALTSTARTUP = &H1E 'non localized common startup
     Global Const CSIDL_COMMON_FAVORITES = &H1F
     Global Const CSIDL_INTERNET_CACHE = &H20
     Global Const CSIDL_COOKIES = &H21
     Global Const CSIDL_HISTORY = &H22
     Global Const CSIDL_COMMON_APPDATA = &H23 'All Users\Application Data
     Global Const CSIDL_WINDOWS = &H24 'GetWindowsDirectory()
     Global Const CSIDL_SYSTEM = &H25 'GetSystemDirectory()
     Global Const CSIDL_PROGRAM_FILES = &H26 'C:\Program Files
     Global Const CSIDL_MYPICTURES = &H27 'C:\Program Files\My Pictures
     Global Const CSIDL_PROFILE = &H28 'USERPROFILE
     Global Const CSIDL_SYSTEMX86 = &H29 'x86 system directory on RISC
     Global Const CSIDL_PROGRAM_FILESX86 = &H2A 'x86 C:\Program Files on RISC
     Global Const CSIDL_PROGRAM_FILES_COMMON = &H2B 'C:\Program Files\Common
     Global Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C 'x86 Program Files\Common on RISC
     Global Const CSIDL_COMMON_TEMPLATES = &H2D 'All Users\Templates
     Global Const CSIDL_COMMON_DOCUMENTS = &H2E 'All Users\Documents
     Global Const CSIDL_COMMON_ADMINTOOLS = &H2F 'All Users\Start Menu\Programs _
     '\Administrative Tools
     Global Const CSIDL_ADMINTOOLS = &H30 '{user}\Start Menu\Programs _
     '\Administrative Tools
     Global Const CSIDL_FLAG_CREATE = &H8000& 'combine with CSIDL_ value to force
     'create on SHGetSpecialFolderLocation()
     Global Const CSIDL_FLAG_DONT_VERIFY = &H4000 'combine with CSIDL_ value to force
     'create on SHGetSpecialFolderLocation()
     Global Const CSIDL_FLAG_MASK = &HFF00 'mask for all possible flag values
     Global Const SHGFP_TYPE_CURRENT = &H0 'current value for user, verify it exists
     Global Const SHGFP_TYPE_DEFAULT = &H1
     
     Global Const MAX_PATH = 260
     Global Const S_OK = 0
     
    '------------------------------
    Sub TestCherche_Chemin()
    Debug.Print Cherche_Chemin(&H10)
    End Sub
    '------------------------------
     
    Public 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
    cordialement

Discussions similaires

  1. Réponses: 1
    Dernier message: 10/04/2006, 09h53
  2. Valeur par défaut dun DBLookupcombobox
    Par lol_adele dans le forum Bases de données
    Réponses: 2
    Dernier message: 13/05/2004, 09h08
  3. Valeur par défaut dans une table objet
    Par Ricky81 dans le forum Oracle
    Réponses: 12
    Dernier message: 18/03/2004, 11h52
  4. Réponses: 2
    Dernier message: 18/10/2003, 14h42
  5. Unique + valeur par défaut
    Par ketalie dans le forum Outils
    Réponses: 4
    Dernier message: 02/07/2003, 15h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo