ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   function wil not update sheet (https://www.excelbanter.com/excel-programming/310544-function-wil-not-update-sheet.html)

Jan Grinwis

function wil not update sheet
 
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.....

Dave Peterson[_3_]

function wil not update sheet
 
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)


Jan Grinwis wrote:

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.....


--

Dave Peterson



All times are GMT +1. The time now is 08:04 AM.

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