Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi
I have tried to write some macro to show the windows username in c a cell, testing on each startup. Function: Function usrname() usrname = Environ("Username") End Function Then a sub: Sub auto_open() Call usrname End Sub In the cell i write =usrname() The problem is that when others open the sheet it still shows my username and not theirs... Anyone have any ideas of what I have done wrong? //Kasper |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
Sometimes Excel remembers the strangest thing. Try clearing any value before executing the function. Function usrname() usrname = vbNull usrname = Environ("Username") End Function You could also try application.username to see if the results are different. They should not be. John "Kasper" wrote in message ... Hi I have tried to write some macro to show the windows username in c a cell, testing on each startup. Function: Function usrname() usrname = Environ("Username") End Function Then a sub: Sub auto_open() Call usrname End Sub In the cell i write =usrname() The problem is that when others open the sheet it still shows my username and not theirs... Anyone have any ideas of what I have done wrong? //Kasper |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Or you can try this setup/code. Just copy it all into a new module and try
it out by calling the ShowUserName sub. Pick the method from the results that appeals to you the most and modify it to put the user's name in your cell. ' This is used by GetUserName() to find the current user's ' name from the API Declare Function Get_User_Name Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long Sub ShowUserName() '3 ways to do pretty much the same thing ' MsgBox GetUserName() ' MsgBox Environ("Username") ' MsgBox Application.UserName MsgBox "GetUserName: " & GetUserName() & vbCrLf _ & "Environ: " & Environ("Username") & vbCrLf _ & "Application.Username: " & Application.UserName, _ vbOKOnly, "UserName Test" End Sub Function GetUserName() As String Dim lpBuff As String * 25 Get_User_Name lpBuff, 25 GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) End Function "Kasper" wrote: Hi I have tried to write some macro to show the windows username in c a cell, testing on each startup. Function: Function usrname() usrname = Environ("Username") End Function Then a sub: Sub auto_open() Call usrname End Sub In the cell i write =usrname() The problem is that when others open the sheet it still shows my username and not theirs... Anyone have any ideas of what I have done wrong? //Kasper |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On 16 Jun., 14:13, JLatham wrote:
Or you can try this setup/code. *Just copy it all into a new module and try it out by calling the ShowUserName sub. *Pick the method from the results that appeals to you the most and modify it to put the user's name in your cell. ' This is used by GetUserName() to find the current user's ' name from the API Declare Function Get_User_Name Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long Sub ShowUserName() '3 ways to do pretty much the same thing ' *MsgBox GetUserName() ' *MsgBox Environ("Username") ' *MsgBox Application.UserName MsgBox "GetUserName: " & GetUserName() & vbCrLf _ *& "Environ: " & Environ("Username") & vbCrLf _ *& "Application.Username: " & Application.UserName, _ *vbOKOnly, "UserName Test" End Sub Function GetUserName() As String * Dim lpBuff As String * 25 * Get_User_Name lpBuff, 25 * GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1) End Function "Kasper" wrote: Hi I have tried to write some macro to show the windows username in c a cell, testing on each startup. Function: Function usrname() usrname = Environ("Username") End Function Then a sub: Sub auto_open() Call usrname End Sub In the cell i write =usrname() The problem is that when others open the sheet it still shows my username and not theirs... Anyone have any ideas of what I have done wrong? //Kasper- Skjul tekst i anførselstegn - - Vis tekst i anførselstegn - Thanks for the answers. |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On 16 Jun., 11:39, Kasper wrote:
Hi I have tried to write some macro to show the windows username in c a cell, testing on each startup. Function: Function usrname() usrname = Environ("Username") End Function Then a sub: Sub auto_open() Call usrname End Sub In the cell i write =usrname() The problem is that when others open the sheet it still shows my username and not theirs... Anyone have any ideas of what I have done wrong? //Kasper Solved the problem using this code: Sub Auto_Open() Sheets(1).Cells(2, 15).Value = Environ("username") End Sub And thereby not having a function... It still irritates me though, that I couldn't get the function to update, when someone else opened the sheet. //Kasper |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
(username v1) | Excel Discussion (Misc queries) | |||
username | Excel Worksheet Functions | |||
Show username in a cell | Excel Discussion (Misc queries) | |||
Show Username | Excel Discussion (Misc queries) | |||
NT Username | Excel Discussion (Misc queries) |