Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2460 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Accès comptes mail Outlook par VBA

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Accès comptes mail Outlook par VBA

n°913939
yan77
Posté le 03-12-2004 à 15:03:54  profilanswer
 

Bonjour,
 
Comment peut-on accéder aux propriétés des comptes mail (nom, login, serveur pop...) de Outlook via VBA ? Quel objet faut utiliser ?
 
Merci d'avance.

mood
Publicité
Posté le 03-12-2004 à 15:03:54  profilanswer
 

n°914145
yan77
Posté le 03-12-2004 à 17:23:44  profilanswer
 


J'ai trouvé un moyen via la base de registres.
Par contre, les modif ne sont prises en compte qu'en relançant Outlook.
Y a-y-il un moyen de faire un espèce de refresh ou reload pour que ça prenne effet immédiatement ?
 

n°919567
snooooop
Posté le 10-12-2004 à 13:01:29  profilanswer
 

heu comment tu fé :)
ca m'interesse GRAVE :)

n°919620
yan77
Posté le 10-12-2004 à 13:58:39  profilanswer
 

Private Const HKEY_CURRENT_USER = &H80000001
 
Private Const REG_SZ = 1
Private Const REG_DWORD = 4
 
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
 
Public Sub ActiverComptesPerso()
    Dim LcBuffer As String
    Dim hKey As Long
    Dim hSousKey As Long
    Dim LcKeyIndex As Long
    Dim LcResult As Long
    Dim LcValueType As Long
    Dim LcDataBufferSize As Long
     
    LcKeyIndex = 0
    RegOpenKey HKEY_CURRENT_USER, "Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts", hKey
    Do
        'Create a buffer
        LcBuffer = String(255, 0)
        'Enumerate the keys
        If RegEnumKeyEx(hKey, LcKeyIndex, LcBuffer, 255, 0, vbNullString, ByVal 0&, ByVal 0& ) <> 0 Then Exit Do
         
        'Open a new key
        RegOpenKey HKEY_CURRENT_USER, "Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts\" & LcBuffer, hSousKey
         
        'est-ce un compte perso ?
        'retrieve information about the key
        LcResult = RegQueryValueEx(hSousKey, "SMTP Email Address", 0, LcValueType, ByVal 0, LcDataBufferSize)
        If LcResult = 0 Then
            'Create a buffer
            LcBuffer = String(LcDataBufferSize, Chr$(0))
            'retrieve the key's content
            LcResult = RegQueryValueEx(hSousKey, "SMTP Email Address", 0, 0, ByVal LcBuffer, LcDataBufferSize)
            If Len(LcBuffer) > 1 Then LcBuffer = Left(LcBuffer, Len(LcBuffer) - 1)
            If InStr("adr1,adr2,...", LcBuffer) > 0 Then
                'activer le compte
                LcResult = RegSetValueEx(hSousKey, "POP3 Skip Account", 0, REG_DWORD, CLng(0), 4)
            End If
        End If
         
        'Close the registry
        RegCloseKey hSousKey
         
        LcKeyIndex = LcKeyIndex + 1
    Loop
    'Close the registry key
    RegCloseKey hKey
    MsgBox "Activés ! Il faut relancer Outlook"
End Sub
 
Public Sub DesactiverComptesPerso()
    Dim LcBuffer As String
    Dim hKey As Long
    Dim hSousKey As Long
    Dim LcKeyIndex As Long
    Dim LcResult As Long
    Dim LcValueType As Long
    Dim LcDataBufferSize As Long
     
    LcKeyIndex = 0
    RegOpenKey HKEY_CURRENT_USER, "Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts", hKey
    Do
        'Create a buffer
        LcBuffer = String(255, 0)
        'Enumerate the keys
        If RegEnumKeyEx(hKey, LcKeyIndex, LcBuffer, 255, 0, vbNullString, ByVal 0&, ByVal 0& ) <> 0 Then Exit Do
         
        'Open a new key
        RegOpenKey HKEY_CURRENT_USER, "Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts\" & LcBuffer, hSousKey
         
        'est-ce un compte perso ?
        'retrieve information about the key
        LcResult = RegQueryValueEx(hSousKey, "SMTP Email Address", 0, LcValueType, ByVal 0, LcDataBufferSize)
        If LcResult = 0 Then
            'Create a buffer
            LcBuffer = String(LcDataBufferSize, Chr$(0))
            'retrieve the key's content
            LcResult = RegQueryValueEx(hSousKey, "SMTP Email Address", 0, 0, ByVal LcBuffer, LcDataBufferSize)
            If Len(LcBuffer) > 1 Then LcBuffer = Left(LcBuffer, Len(LcBuffer) - 1)
            If InStr("adr1,adr2,...", LcBuffer) > 0 Then
                'désactiver le compte
                LcResult = RegSetValueEx(hSousKey, "POP3 Skip Account", 0, REG_DWORD, CLng(1), 4)
            End If
        End If
         
        'Close the registry
        RegCloseKey hSousKey
         
        LcKeyIndex = LcKeyIndex + 1
    Loop
    'Close the registry key
    RegCloseKey hKey
    MsgBox "Desactivés ! Il faut relancer Outlook"
End Sub
 
voilà, faut relancer Outlook après


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Accès comptes mail Outlook par VBA

 

Sujets relatifs
fonction mail ->23 caracteres max.Importer Carnet d'adresse + agenda outlook à partir d'un site web
vba et wordProblème VBA Copier celulles dans autres celulles
Formulaire avec mail multipleenvoyer un mail en CGI sans formulaire
pb avec la fonction mailEnvoi de mail en html... Free me change des balises !
recuperer un Mail pop3 en javaclient mail chez free
Plus de sujets relatifs à : Accès comptes mail Outlook par VBA


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR