1

Hi im looking for a formulla to show User's full name who is opening excel file.it should show that logged in user name. I tried some VBA script and got succesfull but there is one problem that when i run script that time only it Generate pop up windows saying your user name. it should show user name in cell as a date formulla a"=TODAY()". i have this script please anybody help me to show full user name in cell.

Sub GetUserFullName()
    Dim MyOBJ As Object
    On Error Resume Next
    Set MyOBJ = GetObject("WinMgmts:").instancesOf("Win32_NetworkLoginProfile")
    If Err.Number <> 0 Then
      MsgBox "WMI has not been installed, code will be terminated...", vbExclamation, "Windows Management Instrumentation"
      Exit Sub
    End If
    For Each objItem In MyOBJ
        MyMsg = MyMsg & "Welcome To IT Dept   : " & vbCrLf & vbCrLf & objItem.FullName
    Next
    MsgBox MyMsg, vbInformation, "Swapnil (System Admin)"
End Sub
0

1 Answer 1

2

UPD:

Function GetUserFullName() As String
    Dim MyOBJ As Object
    Dim res As String
    On Error Resume Next
    Set MyOBJ = GetObject("WinMgmts:").instancesOf("Win32_NetworkLoginProfile")
    If Err.Number <> 0 Then
      GetUserFullName = "error"
      Exit Function
    End If
    For Each objItem In MyOBJ
        res = res & objItem.FullName
    Next
    GetUserFullName = res
End Function

you can use it in any cell like formula: =GetUserFullName()

Sign up to request clarification or add additional context in comments.

1 Comment

I agree with Mehow, I'd delete the first answer as Application.Username can be changed by anyone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.