PDA

View Full Version : VBA write to registry Win 7



nhmabv
09-15-2012, 11:40 AM
I am currently writing to the registry with the following code under Word VBA 2003 running on XP sp3:

Sub RegSave(MyKey as String, MyVal as String, Optional MyType as String = "REG_SZ")
Dim myWS as Object
Set myWS = CreateObject("WScript.Shell")
myWS.RegWrite (MyKey, MyVal, MyType)
End Sub

This works great, if the key does not exist, it is created. If existing, it is updated with the new value.
However,
Running on Win7 I get an error when calling it where the key does not exist. "Invalid root in registry key"
"HKEY_LOCAL_MACHINE\SOFTWARE\abc\def\"

If I manually create the key by accessing the 64 bit registry by typing at the command line: %systemroot%\syswow64\regedit -m and create the key, my RegRead (which is also a windows scripting registry read function) is able to read it.
However, I need to create and update these key from my VBA application.
I have read a lot on the redirection to WOW6432NODE but I cant fit this into actual code.
A billion thanks for help

gmaxey
09-15-2012, 11:25 PM
Have you looked at or tried:
SaveSetting and GetSetting?

This pair makes writing and retrieving application data in the registry a walk in the park.

nhmabv
09-16-2012, 11:34 AM
Greg,
I am not able to find anything on your site about "SaveSetting"
Mike

gmaxey
09-16-2012, 11:42 AM
Sorry for the confusion. There isn't anything on my site about that specifically. These are built-in VBA statements. Just type them in the editor, select, and press F1.

nhmabv
09-16-2012, 04:37 PM
Greg,
Looks Very interesting.
I have an outside app that needs to read some of these values.
Just exactly where are the settings located? Under HKLM, HKCU ??
Thanks

gmaxey
09-16-2012, 05:06 PM
In the key "VB and VBA Program Settings"

nhmabv
09-16-2012, 05:25 PM
OK,
I found it
You are a genius. Now I can write to the registry in Words' native method.
And thanks a zillion to the billionth power
Mike

nhmabv
09-16-2012, 05:31 PM
One question,
Is there a way to set the default value?
Thanks
Mike