Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Show username on startup

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   Report Post  
Posted to microsoft.public.excel.misc
jaf jaf is offline
external usenet poster
 
Posts: 300
Default Show username on startup

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Show username on startup

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Show username on startup

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Show username on startup

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
(username v1) JJernigan Excel Discussion (Misc queries) 0 June 12th 08 09:13 PM
username robzrob Excel Worksheet Functions 2 May 4th 08 05:59 PM
Show username in a cell bradasley Excel Discussion (Misc queries) 4 June 5th 06 03:34 PM
Show Username Param Excel Discussion (Misc queries) 1 March 11th 06 03:09 PM
NT Username ceemo Excel Discussion (Misc queries) 4 August 2nd 05 04:39 PM


All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"