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

VBA Outlook Discussion :

Créer une macro qui modifie la langue du correcteur d'orthographe


Sujet :

VBA Outlook

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4
    Points : 2
    Points
    2
    Par défaut Créer une macro qui modifie la langue du correcteur d'orthographe
    Bonjour,

    J'utilise outlook 2002.

    Je souhaite créer une macro qui permette de commuter entre dictionnaire français et dictionnaire anglais lorsque l'on utilise le correcteur orthographique de outlook.

    Merci pour votre aide !

  2. #2
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    Bonjour,
    cela doit dépendre si vous utilisez word comme éditeur ou pas.
    il y a des chances que ce soit dans le registre.

    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    Attribute VB_Name = "Module1"
     
     
    ' REGISTRY ACCESS FUNCTIONS
    ' Created by E.Spencer - This code is public domain.
    '
    Option Explicit
    'Security Mask constants
    Public Const READ_CONTROL = &H20000
    Public Const SYNCHRONIZE = &H100000
    Public Const STANDARD_RIGHTS_ALL = &H1F0000
    Public Const STANDARD_RIGHTS_READ = READ_CONTROL
    Public Const STANDARD_RIGHTS_WRITE = READ_CONTROL
    Public Const KEY_QUERY_VALUE = &H1
    Public Const KEY_SET_VALUE = &H2
    Public Const KEY_CREATE_SUB_KEY = &H4
    Public Const KEY_ENUMERATE_SUB_KEYS = &H8
    Public Const KEY_NOTIFY = &H10
    Public Const KEY_CREATE_LINK = &H20
    Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
       KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
       KEY_CREATE_LINK) And (Not SYNCHRONIZE))
    Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
       KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    Public Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
    Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE _
       Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
    ' Possible registry data types
    Public Enum InTypes
       ValNull = 0
       ValString = 1
       ValXString = 2
       ValBinary = 3
       ValDWord = 4
       ValLink = 6
       ValMultiString = 7
       ValResList = 8
    End Enum
    ' Registry value type definitions
    Public Const REG_NONE As Long = 0
    Public Const REG_SZ As Long = 1
    Public Const REG_EXPAND_SZ As Long = 2
    Public Const REG_BINARY As Long = 3
    Public Const REG_DWORD As Long = 4
    Public Const REG_LINK As Long = 6
    Public Const REG_MULTI_SZ As Long = 7
    Public Const REG_RESOURCE_LIST As Long = 8
    ' Registry section definitions
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const HKEY_CURRENT_CONFIG = &H80000005
    Public Const HKEY_DYN_DATA = &H80000006
    ' Codes returned by Reg API calls
    Private Const ERROR_NONE = 0
    Private Const ERROR_BADDB = 1
    Private Const ERROR_BADKEY = 2
    Private Const ERROR_CANTOPEN = 3
    Private Const ERROR_CANTREAD = 4
    Private Const ERROR_CANTWRITE = 5
    Private Const ERROR_OUTOFMEMORY = 6
    Private Const ERROR_INVALID_PARAMETER = 7
    Private Const ERROR_ACCESS_DENIED = 8
    Private Const ERROR_INVALID_PARAMETERS = 87
    Private Const ERROR_NO_MORE_ITEMS = 259
    ' Registry API functions used in this module (there are more of them)
    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 RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult 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, ByVal lpData As String, lpcbData As Long) 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, ByVal lpData As String, lpcbData As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
    Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
    Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
    Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
     
    ' This routine allows you to get values from anywhere in the Registry, it currently
    ' only handles string, double word and binary values. Binary values are returned as
    ' hex strings.
    '
    ' Example
    ' Text1.Text = ReadRegistry(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
    '
    Public Function ReadRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String) As String
     
    Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long, lValueLength As Long, sValue As String, td As Double, TStr2 As String
    Dim i As Integer, TStr1 As String
     
     
    On Error Resume Next
    lResult = RegOpenKey(Group, Section, lKeyValue)
    sValue = Space$(2048)
    lValueLength = Len(sValue)
    lResult = RegQueryValueEx(lKeyValue, Key, 0&, lDataTypeValue, sValue, lValueLength)
    If (lResult = 0) And (Err.Number = 0) Then
       If lDataTypeValue = REG_DWORD Then
          td = Asc(Mid$(sValue, 1, 1)) + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 * Asc(Mid$(sValue, 3, 1)) + &H1000000 * CDbl(Asc(Mid$(sValue, 4, 1)))
          sValue = Format$(td, "000")
       End If
       If lDataTypeValue = REG_BINARY Then
           ' Return a binary field as a hex string (2 chars per byte)
           TStr2 = ""
           For i = 1 To lValueLength
              TStr1 = Hex(Asc(Mid(sValue, i, 1)))
              If Len(TStr1) = 1 Then TStr1 = "0" & TStr1
              TStr2 = TStr2 + TStr1
           Next
           sValue = TStr2
       Else
          sValue = Left$(sValue, lValueLength - 1)
       End If
    Else
       sValue = "Not Found"
    End If
    lResult = RegCloseKey(lKeyValue)
    ReadRegistry = sValue
    End Function
     
    ' This routine allows you to write values into the entire Registry, it currently
    ' only handles string and double word values.
    '
    ' Example
    ' WriteRegistry HKEY_CURRENT_USER, "SOFTWARE\My Name\My App\", "NewSubKey", ValString, "NewValueHere"
    ' WriteRegistry HKEY_CURRENT_USER, "SOFTWARE\My Name\My App\", "NewSubKey", ValDWord, "31"
    '
    Public Sub WriteRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String, ByVal ValType As InTypes, ByVal Value As Variant)
    Dim lResult As Long
    Dim lKeyValue As Long
    Dim InLen As Long
    Dim lNewVal As Long
    Dim sNewVal As String
    On Error Resume Next
    lResult = RegCreateKey(Group, Section, lKeyValue)
    If ValType = ValDWord Then
       lNewVal = CLng(Value)
       InLen = 4
       lResult = RegSetValueExLong(lKeyValue, Key, 0&, ValType, lNewVal, InLen)
    Else
       ' Fixes empty string bug - spotted by Marcus Jansson
       If ValType = ValString Then Value = Value + Chr(0)
       sNewVal = Value
       InLen = Len(sNewVal)
       lResult = RegSetValueExString(lKeyValue, Key, 0&, 1&, sNewVal, InLen)
    End If
    lResult = RegFlushKey(lKeyValue)
    lResult = RegCloseKey(lKeyValue)
    End Sub
     
    ' This routine enumerates the subkeys under any given key
    ' Call repeatedly until "Not Found" is returned - store values in array or something
    '
    ' Example - this example just adds all the subkeys to a string - you will probably want to
    ' save then into an array or something.
    '
    ' Dim Res As String
    ' Dim i As Long
    ' Res = ReadRegistryGetSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", i)
    ' Do Until Res = "Not Found"
    '   Text1.Text = Text1.Text & " " & Res
    '   i = i + 1
    '   Res = ReadRegistryGetSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", i)
    ' Loop
     
    Public Function ReadRegistryGetSubkey(ByVal Group As Long, ByVal Section As String, Idx As Long) As String
    Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long, lValueLength As Long, sValue As String, td As Double
    On Error Resume Next
    lResult = RegOpenKey(Group, Section, lKeyValue)
    sValue = Space$(2048)
    lValueLength = Len(sValue)
    lResult = RegEnumKey(lKeyValue, Idx, sValue, lValueLength)
    If (lResult = 0) And (Err.Number = 0) Then
       sValue = Left$(sValue, InStr(sValue, Chr(0)) - 1)
    Else
       sValue = "Not Found"
    End If
    lResult = RegCloseKey(lKeyValue)
    ReadRegistryGetSubkey = sValue
    End Function
     
    ' This routine allows you to get all the values from anywhere in the Registry under any
    ' given subkey, it currently only returns string and double word values.
    '
    ' Example - returns list of names/values to multiline text box
    ' Dim Res As Variant
    ' Dim i As Long
    ' Res = ReadRegistryGetAll(HKEY_CURRENT_USER, "Software\Microsoft\Notepad", i)
    ' Do Until Res(2) = "Not Found"
    '    Text1.Text = Text1.Text & Chr(13) & Chr(10) & Res(1) & " " & Res(2)
    '    i = i + 1
    '    Res = ReadRegistryGetAll(HKEY_CURRENT_USER, "Software\Microsoft\Notepad", i)
    ' Loop
    '
    Public Function ReadRegistryGetAll(ByVal Group As Long, ByVal Section As String, Idx As Long) As Variant
    Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long
    Dim lValueLength As Long, lValueNameLength As Long
    Dim sValueName As String, sValue As String
    Dim td As Double
    On Error Resume Next
    lResult = RegOpenKey(Group, Section, lKeyValue)
    sValue = Space$(2048)
    sValueName = Space$(2048)
    lValueLength = Len(sValue)
    lValueNameLength = Len(sValueName)
    lResult = RegEnumValue(lKeyValue, Idx, sValueName, lValueNameLength, 0&, lDataTypeValue, sValue, lValueLength)
    If (lResult = 0) And (Err.Number = 0) Then
       If lDataTypeValue = REG_DWORD Then
          td = Asc(Mid$(sValue, 1, 1)) + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 * Asc(Mid$(sValue, 3, 1)) + &H1000000 * CDbl(Asc(Mid$(sValue, 4, 1)))
          sValue = Format$(td, "000")
       End If
       sValue = Left$(sValue, lValueLength - 1)
       sValueName = Left$(sValueName, lValueNameLength)
    Else
       sValue = "Not Found"
    End If
    lResult = RegCloseKey(lKeyValue)
    ' Return the datatype, value name and value as an array
    ReadRegistryGetAll = Array(lDataTypeValue, sValueName, sValue)
    End Function
     
    ' This routine deletes a specified key (and all its subkeys and values if on Win95) from the registry.
    ' Be very careful using this function.
    '
    ' Example
    ' DeleteSubkey HKEY_CURRENT_USER, "Software\My Name\My App"
    '
    Public Function DeleteSubkey(ByVal Group As Long, ByVal Section As String) As String
    Dim lResult As Long, lKeyValue As Long
    On Error Resume Next
    lResult = RegOpenKeyEx(Group, vbNullChar, 0&, KEY_ALL_ACCESS, lKeyValue)
    lResult = RegDeleteKey(lKeyValue, Section)
    lResult = RegCloseKey(lKeyValue)
    End Function
     
    ' This routine deletes a specified value from below a specified subkey.
    ' Be very careful using this function.
    '
    ' Example
    ' DeleteValue HKEY_CURRENT_USER, "Software\My Name\My App", "NewSubKey"
    '
    Public Function DeleteValue(ByVal Group As Long, ByVal Section As String, ByVal Key As String) As String
    Dim lResult As Long, lKeyValue As Long
    On Error Resume Next
    lResult = RegOpenKey(Group, Section, lKeyValue)
    lResult = RegDeleteValue(lKeyValue, Key)
    lResult = RegCloseKey(lKeyValue)
    End Function
    ' =====================================================================================================================================
    ' GET/SET SPELLING LANGUAGE FOR OUTLOOK 2003
    '
    ' Created by D.Hlad - This code is public domain
    '
    Sub GetCurrentSpellingLanguage()
     
    Dim CurrentSpellingLanguage As String
     
        CurrentSpellingLanguage = ReadRegistry(HKEY_CURRENT_USER, "Software\Microsoft\Office\11.0\Outlook\Options\Spelling\", "Speller")
     
    End Sub
    Sub SetSpellingLanguage(LanguageCode As String)
     
    Dim NewSpellingLanguage As String
     
        NewSpellingLanguage = LanguageCode & "\Normal"
     
        WriteRegistry HKEY_CURRENT_USER, "Software\Microsoft\Office\11.0\Outlook\Options\Spelling\", "Speller", ValString, NewSpellingLanguage
     
    End Sub
     
    Sub SetLanguageUK()
     
        SetSpellingLanguage ("2057")
     
    End Sub
     
    Sub SetLanguageUS()
     
        SetSpellingLanguage ("1033")
     
    End Sub
     
    Sub SetLanguageES()
     
        SetSpellingLanguage ("3082")
     
    End Sub
    Sub SetLanguageHR()
     
        SetSpellingLanguage ("1050")
     
    End Sub
    Sub SetLanguageCAT()
     
        SetSpellingLanguage ("1027")
     
    End Sub
    Sub SetLanguagePOR()
     
        SetSpellingLanguage ("2070")
     
    End Sub
    Oliv'

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    merci beaucoup pour votre réponse. Le code compile, j'arrive à éxécuter le macro, mais cependant, le langue utilisée par le correcteur orthographique ne change pas pour autant. Avez vous une idée ?

    Olivier.

  4. #4
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    Bonjour,
    OUtils macro/sécurité mettre à moyen.

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    Oui, en effet, ça a marché. J'arrive maintenant a exécuter la macro et je vois bien la valeur de la variable 'speller' changée dans la base de registre, mais lorsque je lance le correcteur orhtographique, la langue utilisée est toujours la même ! C'est tout de même bizarre. En tout cas, toute aide est la bienvenue.

    Olivier.

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4
    Points : 2
    Points
    2
    Par défaut
    Ok. Ca marche !!!
    Merci beaucoup. En fait j'utilise Outlook 10 (et non pas 11). Il a donc suffit de mettre le bon numéro de version d'Outlook dans les fonctions pour que cela fonctionne parfaitement maintenant.

    Merci pour votre aide précieuse,
    Bonne journée,
    Olivier.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2010] Créer une macro pour modifier la mise en page
    Par tben08 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 09/01/2013, 20h51
  2. [XL-2010] Créer une macro qui previent si le fichier a été modifié
    Par Philippe76 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 13/07/2011, 23h24
  3. créer une macro qui renvoie à une cellule vide
    Par cachou52fr dans le forum Macros et VBA Excel
    Réponses: 20
    Dernier message: 17/06/2011, 14h11
  4. [WD-2007] Créer une macro qui rempli des etiquettes automatiquement
    Par damienedme dans le forum VBA Word
    Réponses: 1
    Dernier message: 03/09/2009, 12h03
  5. Créer une macro qui reproduit vers le bas
    Par Jimy6000 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 24/01/2008, 10h43

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