Results 1 to 8 of 8

Thread: VBA write to registry Win 7

  1. #1
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location

    VBA write to registry Win 7

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,357
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location
    Greg,
    I am not able to find anything on your site about "SaveSetting"
    Mike

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,357
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location
    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

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,357
    Location
    In the key "VB and VBA Program Settings"
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location
    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

  8. #8
    VBAX Regular
    Joined
    Apr 2012
    Posts
    24
    Location
    One question,
    Is there a way to set the default value?
    Thanks
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •