"Refreshing" functions when spreadsheet opens

J

Jumbo Shrimps Jr

The following code allows me to type =fOSUserName()
in a cell and the name of the current logged on user
is displayed.
When someone else opens the spreadsheet, the name of the
last person who opened the spreadsheet appears (not the
current user as I thought) in the cell until the function
is copied to a new cell, when the current logged on user's
name appears in the new cell.

Is there any F9-type way to refresh cells so that functions
are refreshed when the spreadsheet is opened?

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

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)

Else

fOSUserName = vbNullString
End If

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

macro help 2
VBA Code to Login to Excel 1
Update form field 2
Capitalise 6
Update username 6
Problem with VBcode in Excel 2
Retrieving and setting user logon name in a form 2
Porting from 2003 to 2007 6

Top