Note |
|---|
| Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination. |
You can read the current user's logon ID using the GetCurrent method of the WindowsIdentity object to represent the current user. You can then display the user's logon ID in a named range on a Microsoft Office Excel 2003 worksheet.
To display the current user's logon ID in a named range
-
Get the user's logon ID.
Dim user As System.Security.Principal.WindowsIdentity
user = System.Security.Principal.WindowsIdentity.GetCurrent()
System.Security.Principal.WindowsIdentity user;
user = System.Security.Principal.WindowsIdentity.GetCurrent();
-
Create a NamedRange control named userID and display the user's login ID.
Dim userID As Microsoft.Office.Tools.Excel.NamedRange
userID = Me.Controls.AddNamedRange(Me.Range("A1"), "userID")
userID.Value2 = user.Name
Microsoft.Office.Tools.Excel.NamedRange userID;
userID = this.Controls.AddNamedRange(this.Range["A1", missing], "userID");
userID.Value2 = user.Name;
Compiling the Code
Robust Programming
The following conditions might cause an exception:
See Also