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!
Please include here a material /sample working code/ to WRITE registry values on selected path - VBA code. Thank you in advance!
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
ヅ haha... You're very welcome, Antonio.
Sorry D, it's more difficult to write than retrieve. Best of luck.
see http://vba-corner.livejournal.com/3054.html for writing to the reg
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!