« Select first empty cell: VBA Excel | Main | Rename lots of sheets: VBA Excel »
Sunday
Jul152007

Example of retreiving values from registry: VBA Excel

 Sub Read_registry_Value()
    Dim Shell As Object
    Dim keyname As String
    Dim value As String
    Dim keyvalue As String

 

    keyname = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\" & _
              "Control\ComputerName\ActiveComputerName\"
             

    value = "ComputerName"

 

    Set Shell = CreateObject("wscript.shell")
    On Error Resume Next
    keyvalue = Shell.regread(keyname & value)
    If Err.Number 0 Then
        MsgBox "Invalid Registry Entry"
    Else
        MsgBox keyvalue
    End If
    On Error GoTo 0
End Sub

 

Reader Comments (6)

Excellent! Thank you!

October 31, 2008 | Unregistered CommenterDDimitrov

Please include here a material /sample working code/ to WRITE registry values on selected path - VBA code. Thank you in advance!

October 31, 2008 | Unregistered CommenterDDimitrov

I just want to say thank you for this bit of code. Its worth every penny and it has saved me hours of searching..
Thank you..
Antonio

August 4, 2009 | Unregistered CommenterAntonio Garcia

ヅ haha... You're very welcome, Antonio.

Sorry D, it's more difficult to write than retrieve. Best of luck.

November 19, 2010 | Registered CommenterGleb

see http://vba-corner.livejournal.com/3054.html for writing to the reg

August 2, 2011 | Unregistered CommenterKristof

Thank for your time to share us this discuss, i have some opinion on the <a href="http://www.dressaler.com/" title="Formal Dresses">Formal Dresses</a>, I feel so stronl about your article, and learning more on this topic, then it is so good, Do you have time visit us <a href="http://www.dressaler.com/wedding-party-dress/bridesmaid-dresses.html" title="Wedding Bridesmaid Dresses">Wedding Bridesmaid Dresses</a>.I will bookmark your blog and have my kids check up here frequently <a href="http://www.dressaler.com/wedding-party-dress/junior-bridesmaid-dresses.html" title="Junior Bridesmaid Dresses">Junior Bridesmaid Dresses</a>. I’m very certain they will understand lots of new stuff here than anybody else. I do appreciate that youve added relevant and intelligent commentary here though. Thank you!

January 5, 2012 | Unregistered CommenterFormal Dresses

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Textile formatting is allowed.