Adding a registry key using VBA.
Posted on 2014-01-09
I would like to add a trusted location key to the registry using vba.
I am using the following vba code to determine if the registry key already exists:
If RegKeyExists("HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\BEApplication\") = False Then
' Code for adding registry key
' Key exists - do nothing
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
'key was found
RegKeyExists = True
'key was not found
RegKeyExists = False
The above code works, returning True if the registry key exists and False if it does not.
I have created a .reg file for adding the registry key. The contents of the .reg file are as follows:
Windows Registry Editor Version 5.00
I can click on this .reg file and the registry key gets added successfully.
How do I accomplish the same thing via vba.