Awill
Awill

Reputation: 117

display a user's first name in a message box

I am having trouble figuring out how to identify only the first name of the user in a message box using VBA. I have a code to prompt a message box on workbook open to allow administrative access according to the user's name with application.username

I want to make it a bit more personalized with just the first name of the user with a greeting. I know you can easily do this with a formula using left() and find() but I'm unsure how to translate that within VBA.

thanks so much for any help

Upvotes: 2

Views: 7468

Answers (2)

Gary's Student
Gary's Student

Reputation: 96781

Consider:

Sub hgfds()
    MsgBox Split(Application.UserName, " ")(0)
End Sub

enter image description here

Upvotes: 4

Danny Cullen
Danny Cullen

Reputation: 1832

You use the ampersand to concatenate strings in VBA, for example.

Dim Name As String
Name = "Hello " & application.username
MsgBox Name

You can use a split() function to split by a space to only get their first name.

Upvotes: 3

Related Questions