Read and Write Windows Registry with VBA

Sep 03, 2007 15:34

VBA offers the functions GetSetting, SaveSetting, GetAllSettings and DeleteSetting for reading and writing the Windows Registry. (For detailed info see the Microsoft VBA help for these functions or look at the MSDN)

But unfortunately you can't access the entire registry, only the path HKEY_CURRENT_USER\Software\VB and VBA Program Settings\. So you ( Read more... )

word, windows_scripting, excel, ms_office, windows, vba, registry

Leave a comment

Comments 4

Just what was needed anonymous June 26 2009, 17:00:58 UTC
This is exactly what I needed to be able to create Access Database code that would check the registry to help link backend tables through VBA code.
I have a program that goes to 12 different locations and each location uses it's own backend. Of course, the backend address/URL in each location is different.
I had started to use a database table to make updating of the links easier, but it has drawbacks if a WAN connection is involved in the first link.
Using a registry check was a better answer but I wanted the information in HKLM and not HKCU. Your code provided the means to make it happen.
I still have some fine tuning to do, but the solution is more elegant and will make program updates easier.

Reply


AWESOME DUDE! anonymous July 25 2009, 20:53:34 UTC
i really appreciate your work. i rewrote the code to stop outlook express from auto running the compacting file dialog box-which opens after opening OE 100 times - and was screwing up my automation. I just found the "Compact Check Count" key, removed all code that could screw up my registry (by accident) and voila. Beauty that couldn't have been done withoutcha!

Sub compactCheckCountRegistryChange()
Dim myRegKey As String
Dim myValue As String
Dim myAnswer As Integer

myRegKey = "HKEY_USERS\ (find your own numbers) \Identities\{ (find your own numbers) }\Software\Microsoft\Outlook Express\5.0\Compact Check Count"

'check if key exists
If RegKeyExists(myRegKey) = True Then

If RegKeyRead(myRegKey) > 95 Then
RegKeySave myRegKey, 1
End If
Else

MsgBox "Check Sub compactCheckCountRegistryChange. Outlook Express -Compact Check Count- registry key cannot be found."

End If

End Sub

Reply


Varieties anonymous November 4 2010, 04:43:31 UTC
Given that this is creating a scripting shell, you could also just as easily call an instance of "reg.exe" and call it with whatever parameters suit your needs...

I'm also wondering whether this better or worse than declaring the advapi32.dll routines in VBA. both have portability issues...

Reply


no HKLM read / write ext_3322733 September 28 2015, 07:26:19 UTC
Hi,

This does not work when trying to read / write registry in HKLM on Windows 7?

Any hints oh how to read / write HLM keys from VBA (more particularly from Access) on Windows 7 ?

Cheers,
L@u

Reply


Leave a comment

Up