+ Reply to Thread
Results 1 to 5 of 5

How to use VBA to read a key value in Registry

  1. #1
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    How to use VBA to read a key value in Registry

    I want to use VBA to read a value from an app-specific key that I have already added to the Registry (HKCU) using Regedit. It's a simple, single string value. I have found various code samples, snippets, and instructions; but so far I have not been able to adapt any of them to work in my application. I believe there is a fairly simple routine (2 or 3 lines) to do this, as long as the key is in HKCU. Does the key also have to be in a specific path in HKCU? If yes, I can put it there. I would be grateful to be provided with the code, or pointed to a web page with code and instructions.

    Thanks in advance. I use Excel 2016, with fully up-to-date Windows10.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to use VBA to read a key value in Registry

    VBA cannot directly read the entire registry, only it's own registry settings. But you can work around that using the Window Shell since that tool has the ability to read and write to the entire registry.

    Check this out.
    http://www.cpearson.com/excel/registry.htm
    http://vba-corner.livejournal.com/3054.html
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: How to use VBA to read a key value in Registry

    Thanks JBeaucaire,

    I had been to both websites you show; I prepared the following code based on Live Journal's first snippet:
    Please Login or Register  to view this content.
    It returns "", can't find the key. When I comment out On Error the function crashes showing error code '-2147024894(80070002)' "Unable to open (specified key) for reading".
    I have double checked the key that I added via Regedit. Can you tell from this info what I'm doing wrong?

    Thanks

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to use VBA to read a key value in Registry

    You need a '\' at the end of KeyPath.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    12-05-2006
    Location
    Philadelphia PA
    MS-Off Ver
    Office 365
    Posts
    81

    Re: How to use VBA to read a key value in Registry

    Thanks, Norie, that did it! Now how do I mark the thread as Solved?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using VBA and WMI to read registry
    By badducchio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-24-2011, 04:10 PM
  2. Excel 2007 : Need Help With A Registry
    By AgentDirtySanchez in forum Excel General
    Replies: 3
    Last Post: 06-26-2010, 09:32 PM
  3. Reading from Registry
    By Big Rick in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-26-2007, 01:53 PM
  4. [SOLVED] Registry Keys
    By EA in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2006, 05:10 PM
  5. Read Registry Keys (and possibly write)
    By Mike Iacovou in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-08-2006, 12:10 PM
  6. Automation & Registry
    By AA2e72E in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-10-2006, 06:30 PM
  7. [SOLVED] Search and read registry for particular external application
    By KS Wong in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2005, 03:53 PM
  8. [SOLVED] Reading the Registry
    By JK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2005, 06:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1