Application.UserName Property

Project Developer Reference

Returns or sets the name of the current user. Read/write String.

Syntax

expression.UserName

expression   A variable that represents an Application object.

Return Value
String

Remarks

Use the UserName property to customize Microsoft Office Project 2007 options or macros for a particular user.

Suppose you have written a macro called

Visual Basic for Applications
  PrintReport

that prints the report Mine.mpp when you press CTRL+R, but another user wants to use the same shortcut keys to print the report Yours.mpp. You can edit the

Visual Basic for Applications
  PrintReport

macro so it checks the UserName property and then prints Mine.mpp if you are the current user or prints Yours.mpp if you are not.

By default, the UserName property equals the Author property.

Example
The following example sets preferences in Office Project 2007 according to the name of the current user.

Visual Basic for Applications
  Sub GetUserName()
' Prompt user for his or her name.
<strong class="bterm">UserName</strong> = InputBox$("What's your name?", , UserName)

' If user is Tamara, then set certain preferences.
If <strong class="bterm">UserName</strong> = "Tamara" Then
    DisplayScheduleMessages = False
    BarRounding On:=False
    Calculation = True
' If user is not Tamara, then set default preferences.
Else
    DisplayScheduleMessages = True
    BarRounding On:=True
    Calculation = False
End If

End Sub

See Also