Const HKEY_CURRENT_USER = &H80000001
Const WMICONST = "winmgmts:{impersonationlevel=impersonate}!root\default:"
Const sMainRegKey = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\" & _
"Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\"
Private Sub WriteSMTP_VBAX()
Dim nRet, objRegistry As Object
Set objRegistry = GetObject(WMICONST & "StdRegProv")
'Change SMTP server to mail.vbaexpress.com
nRet = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, sMainRegKey & "00000003", "SMTP Server ", _
Array( _
Asc("m"), 0, Asc("a"), 0, Asc("i"), 0, Asc("l"), 0, _
Asc("."), 0, _
Asc("v"), 0, Asc("b"), 0, Asc("a"), 0, _
Asc("e"), 0, Asc("x"), 0, Asc("p"), 0, Asc("r"), 0, Asc("e"), 0, Asc("s"), 0, Asc("s"), 0, _
Asc("."), 0, _
Asc("c"), 0, Asc("o"), 0, Asc("m"), 0, 0, 0))
End Sub
The code above accesses the correct hive, but it creates a new key in the folder. Strangely, even if an SMTP key already exists, it will create another one without writing over the existing. (Picture attached.) I've been running this from Excel and opening Outlook afterwards, but no luck in getting it to take.