• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Read and change a registry key using VBA

Slipstick Systems

› Developer › Read and change a registry key using VBA

Last reviewed on May 5, 2014     1 Comment

Use this macro to read a registry key from the registry and change it, if desired. In the examples below, to change the default FileAs format for contacts or toggle the Mark My Comments option off and on.

To use it, you'll need to get the key you want to change from the registry. If you are writing to the registry, the value type of Optional i_Type As String = "REG_DWORD") may need to be updated to the correct type of value.

Read, Edit, Save Registry values

Use these functions with macros (examples below) to change registry values. These functions set or change DWORD values. If you need to change string or binary values, you'll need to change the type in the RegKeySave function.


'reads the value for the registry key i_RegKey
'if the key cannot be found, the return value is ""
Function RegKeyRead(i_RegKey As String) As String
Dim myWS As Object

  On Error Resume Next
  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'read key from registry
  RegKeyRead = myWS.RegRead(i_RegKey)
End Function

'sets the registry key i_RegKey to the
'value i_Value with type i_Type
'if i_Type is omitted, the value will be saved as string
'if i_RegKey wasn't found, a new registry key will be created

' change REG_DWORD to the correct key type
Sub RegKeySave(i_RegKey As String, _
               i_Value As String, _
      Optional i_Type As String = "REG_DWORD")
Dim myWS As Object

  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'write registry key
  myWS.RegWrite i_RegKey, i_Value, i_Type

End Sub

'returns True if the registry key i_RegKey was found
'and False if not
Function RegKeyExists(i_RegKey As String) As Boolean
Dim myWS As Object

  On Error GoTo ErrorHandler
  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'try to read the registry key
  myWS.RegRead i_RegKey
  'key was found
  RegKeyExists = True
  Exit Function
  
ErrorHandler:
  'key was not found
  RegKeyExists = False
End Function

Choose from multiple values

Use this sample to display a value when multiple options exist, and provides an input box for you to enter the DWORD value, with confirmation that you want to make the change. See the notes in the RegKeySave function if you need to change string or binary values.

This sample macro changes the default File as format of contacts.

You'll need the functions above (RegKeyRead, RegKeySave, RegKeyExists) to use this code, as well as the correct registry key for your version of Outlook.

Sub CheckFileAsFormat()
Dim myRegKey As String
Dim myValue As String
Dim myFileAs As String
Dim myAnswer As Integer

  'get registry key to work with
  myRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Contact\FileAsOrder"
  If myRegKey = "" Then Exit Sub
  'check if key exists
  If RegKeyExists(myRegKey) = True Then
    'key exists, read it
    myValue = RegKeyRead(myRegKey)
    If myValue = 14870 Then myFileAs = "Company"
    If myValue = 32791 Then myFileAs = "Last, First"
    If myValue = 32792 Then myFileAs = "Company (Last, First)"
    If myValue = 32793 Then myFileAs = "Last, First (Company)"
    If myValue = 32823 Then myFileAs = "First Last"
   
    
    'display result and ask if it should be changed
    myAnswer = MsgBox("The registry value for the key """ & _
               myRegKey & """is """ & myFileAs & vbCrLf & _
               "Do you want to change it?", vbYesNo)
  Else
    'key doesn't exist, ask if it should be created
    myAnswer = MsgBox("The registry key """ & myRegKey & _
               """ could not be found." & vbCr & vbCr & _
               "Do you want to create it?", vbYesNo)
  End If
  If myAnswer = vbYes Then
    'ask for new registry key value

    myValue = InputBox("Please enter new value: " & vbCrLf & _
    "14870 = Company" & vbCrLf & _
    "32791 = Last, First" & vbCrLf & _
    "32792 = Company (Last, First)" & vbCrLf & _
    "32793 = Last, First (Company)" & vbCrLf & _
    "32823 = First Last", myRegKey, myValue)
    If myValue <> "" Then
      RegKeySave myRegKey, myValue
      MsgBox "Registry key saved."
    End If   
  Else
  End If
End Sub

Enable or Disable Registry Values

This is a simple example and switches the DWORD value between 1 and 0 (to set the option on/enabled or off/disabled). You can use it with any value that is either enabled or disabled.

You'll need the functions above (RegKeyRead, RegKeySave, RegKeyExists) to use this code, as well as the correct registry key for your version of Outlook.

This code sample toggles the Mark My Comments With option on or off in Outlook 2013.

Not all options that are toggled on and off can be changed by code, some may require Outlook to be restarted if you don't use the Options dialog to make the change.

Sub ChangeCommentWith()

Dim myRegKey As String
Dim myValue As String
Dim myFileAs As String
Dim myAnswer As Integer
 
  'get registry key to work with
  myRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Common\MailSettings\MarkComments"
  If myRegKey = "" Then Exit Sub
  'check if key exists
  If RegKeyExists(myRegKey) = True Then
    'key exists, read it
    myValue = RegKeyRead(myRegKey)
    If myValue = 1 Then myValue = "0" Else myValue = 1
      Else
    myValue = 1
   End If
  
    If myValue <> "" Then
      RegKeySave myRegKey, myValue
      MsgBox "Registry key set to " & myValue
  End If

End Sub
End Sub

More Information

The above macros are an edited version of the macros at Read and Write Windows Registry with VBA.

Read and change a registry key using VBA was last modified: May 5th, 2014 by Diane Poremsky

Related Posts:

  • Bulk Change Contact's FileAs Format to Match Outlook's Default Setting
  • Change the Search Provider in Office 2013
  • Get Outlook's Internet Headers using VBA or PowerShell
  • Excel Files Won't Display in Reading Pane

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
1 Comment
newest
oldest most voted
Inline Feedbacks
View all comments

computingfroggy
September 30, 2015 3:41 pm

Hi,

This does not work with Windows 7 and Office 2010 to read / write registry key in HKLM !
Any solution to read / write HKLM registry from MS Access ?

Cheers,
L@u

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 36

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • How to Hide or Delete Outlook's Default Folders
  • Removing Suggested Accounts in New Outlook
  • Reset the New Outlook Profile
  • This operation has been cancelled due to restrictions
  • iCloud error: Outlook isn't configured to have a default profile
  • Adjusting Outlook's Zoom Setting in Email
  • Online Services in Outlook: Gmail, Yahoo, iCloud, AOL, GoDaddy
  • Add Holidays to Outlook's Calendar
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment