I have code on my web site to work with the Registry. See
http://www.cpearson.com/Excel/Registry.htm for the code. I also have an
ActiveX DLL that wraps up all the registry functions in a nice VBA-friendly
package. See
http://www.cpearson.com/Excel/registryworx.aspx for info and
free download.
I think the key you are looking for is
HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserName
The code to retrieve this, using the RegistryWorx DLL, is shown below. You
can call it from a worksheet cell with =MyFullName() or from other code with
Dim MyName As String
MyName = MyFullName()
If MyName = vbNullString Then
MsgBox "Cannot get name"
Else
MsgBox "Name: " & MyName
End If
Function MyFullName() As String
' requires a Reference to RegistryWorx.DLL
' reads value HKCU\Software\Microsoft\Office\Common\UserInfo\UserName
Dim BaseKey As Long
Dim KeyName As String
Dim ValueName As String
Dim ValueValue As Variant
Dim RW As RegistryWorx.Root
Set RW = New RegistryWorx.Root
BaseKey = &H80000001 ' = HKEY_CURRENT_USER
KeyName = "Software\Microsoft\Office\Common\UserInfo"
ValueName = "UserName"
ValueValue = RW.RegistryGetValue( _
BaseKey:=BaseKey, _
KeyName:=KeyName, _
ValueName:=ValueName)
If IsNull(ValueValue) = True Then
Debug.Print "Cannot read value or value not found: " & vbCrLf & _
"Value Name: " & ValueName & vbCrLf & _
"Key: " & KeyName
MyFullName = vbNullString
Else
MyFullName = ValueValue
End If
End Function
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)