how to update registery values for Excel forware using VBA

I would like to update the following Company detail from my machine using VBA

I want the company name to be changed from Chizmagonta to  Yamaushikasa

registry path HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo
"Company"="Chizmagonta"
"UserName"="Flora"
"UserInitials"="FL"

there are lots of arcitles in the web for updaring registry , as i do not know which one is correct one so that i do not mess up my registry

thanks.
LVL 6
FloraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zalazarCommented:
The following code will accomplish this.
It does verify if the registry entries exists before writing the new values.
Sub UpdateOfficeRegValues()

  Dim WshShell
  Set WshShell = CreateObject("WScript.Shell")
  vSuccess = 0

  On Error Resume Next
  sCompany = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company")
  If Err.Number = 0 Then
    WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\Company", "Chizmagonta", "REG_SZ"
    If Err.Number = 0 Then
      vSuccess = vSuccess + 1
    Else
      MsgBox "Error writing registry value Company", 48
      Err.Clear
    End If
  Else
    MsgBox "Error reading registry value Company", 48
    Err.Clear
  End If

  sUserInitials = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserInitials")
  If Err.Number = 0 Then
    WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserInitials", "Flora", "REG_SZ"
    If Err.Number = 0 Then
      vSuccess = vSuccess + 1
    Else
      MsgBox "Error writing registry value UserInitials", 48
      Err.Clear
    End If
  Else
    MsgBox "Error reading registry value UserInitials", 48
    Err.Clear
  End If

  sUsername = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserName")
  If Err.Number = 0 Then
    WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserName", "FL", "REG_SZ"
    If Err.Number = 0 Then
      vSuccess = vSuccess + 1
    Else
      MsgBox "Error writing registry value UserName", 48
      Err.Clear
    End If
  Else
    MsgBox "Error reading registry value UserName", 48
    Err.Clear
  End If

  If vSuccess = 3 Then
    MsgBox "Office registry values successfully updated", 64
  Else
    MsgBox "There was an error while updating registry values", 48
  End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FloraAuthor Commented:
thank you very much.

works
0
zalazarCommented:
You're welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.