ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to add username in excel (https://www.excelbanter.com/excel-programming/425121-how-add-username-excel.html)

Dave VB logic for excel

How to add username in excel
 
Hello,

I hope you guys can help me. Im currently working in excel sheet. I would
like to know tha formula where the shee should capture the username from the
system or the licence which allocated to the user. What is the function or vb
formula?

Thank you in advanced.

cupboy

How to add username in excel
 
If you're using C#...

rangeXX.Value2 = Environment.UserName;




"Dave VB logic for excel" wrote:

Hello,

I hope you guys can help me. Im currently working in excel sheet. I would
like to know tha formula where the shee should capture the username from the
system or the licence which allocated to the user. What is the function or vb
formula?

Thank you in advanced.


Tom Hutchins

How to add username in excel
 
Here are a couple of alternatives. The simplest way is
Dim UserName as string
UserName = Environ("USERNAME")

Here is another way to retrieve the user's LAN ID using an API call. Copy
this code into a general VBA module in your workbook:

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long

Public Function UserName() As String
Dim Buffer As String * 100
Dim BuffLen As Long
On Error GoTo UNerr
BuffLen = 100
GetUserName Buffer, BuffLen
UserName = Left(Buffer, BuffLen - 1)
Exit Function
UNerr:
UserName = vbNullString
End Function

You would call it like this in VBA:
Sub AAAAA()
MsgBox UserName()
End Sub

Or, from a worksheet cell:
=UserName()

Finally, you could also try retrieving Application.UserName, which is the
name entered on the Tools Options General tab.

If you are new to user-defined functions (macros), this link to Jon
Peltier's site may be helpful:
http://peltiertech.com/WordPress/200...e-elses-macro/

Hope this helps,

Hutch

"Dave VB logic for excel" wrote:

Hello,

I hope you guys can help me. Im currently working in excel sheet. I would
like to know tha formula where the shee should capture the username from the
system or the licence which allocated to the user. What is the function or vb
formula?

Thank you in advanced.



All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com