function wil not update sheet

J

Jan Grinwis

I have a worksheet with a username function in it. The cell with the
function call =fOSUserName() will not update if another user is using
the worksheet. If I manualy edit and enter the cell again it works
great.

If I calculate the sheet at start with the auto_open macro it makes no
difference, it wil keep the last saved name.

What could be wrong??

In the future I want to use this function in a shared file is....Also
a problem??

The Function looks and macro looks like: (by the way this comes from
this great group....)
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 = ""
End If
End Function

Sub GetUserNameTest()
MsgBox fOSUserName
End Sub

Sub auto_open()
Worksheets("blad1").Calculate
End Sub

Jan.....
 
D

Dave Peterson

I would have thought that the function would evaluate correctly, but...

This is untested (I only have one logon id):

How about:

sub auto_open
with worksheets("blad1")
.cells.Replace What:="=", Replacement:="=", _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False
.calculate '???
end with
end sub

It's just doing an Edit|replace
what: = (equal sign)
with: = (equal sign)
replace all.

This function does get the logon name--so if both users were using the same pc
(and the first didn't logoff, then it won't help.)

But there is an application.username
(it picks up the name from Tools|Options|general tab|user name box)
 

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


Top