Windows 7 VBA write to registry Win 7

mhnwin7

New Member
Joined
Sep 15, 2012
Messages
2
I am not able to figure out how to write to the registry in VB or VBA.
I tried using the windows APi and WS.Script, both work in the XP environment, but not Win7

I just need to create a key and set the key value. MY current code I am using can read the key if I manually create it.

I have read a ton of stuff about the redirection in the registry in win7 but nothing translates to just wow to create a key in the windows 7 registry in Visual Basic.
A billion thanks for your help
 
Solution
To write to the Windows registry in Visual Basic or VBA, you can make use of the Microsoft Win32 API functions specifically designed for this purpose. When dealing with registry operations in newer versions of Windows like Windows 7, you need to consider the user permissions and the correct way to access the registry due to User Account Control (UAC) restrictions. Here is a basic example in VBA that demonstrates how to create a key in the Windows registry:
Code:
Sub WriteToRegistry() Dim regKey As Object Dim keyValue As String ' Define the key path and the value to set keyPath = "SOFTWARE\YourAppName" keyValue = "YourValue" ' Access the registry Set regKey = CreateObject("WScript.Shell") regKey.RegWrite "HKEY_LOCAL_MACHINE\" & keyPath...
To write to the Windows registry in Visual Basic or VBA, you can make use of the Microsoft Win32 API functions specifically designed for this purpose. When dealing with registry operations in newer versions of Windows like Windows 7, you need to consider the user permissions and the correct way to access the registry due to User Account Control (UAC) restrictions. Here is a basic example in VBA that demonstrates how to create a key in the Windows registry:
Code:
Sub WriteToRegistry() Dim regKey As Object Dim keyValue As String ' Define the key path and the value to set keyPath = "SOFTWARE\YourAppName" keyValue = "YourValue" ' Access the registry Set regKey = CreateObject("WScript.Shell") regKey.RegWrite "HKEY_LOCAL_MACHINE\" & keyPath, keyValue, "REG_SZ" MsgBox "Registry key created successfully!" End Sub
In this script:
  • Replace "YourAppName" with the key path you want to create.
  • Replace "YourValue" with the value you want to set for that key.
Ensure that you run your VBA script with the necessary administrator permissions to make changes to the registry in Windows 7. If you face permissions issues, you might need to run your script with elevated privileges. You can do this by right-clicking on your script and selecting "Run as administrator." Remember, working with the Windows registry can be risky, so always make sure to back up the registry before making changes. Feel free to try out this script and let me know if you encounter any issues or if you need further assistance!
 
Solution