A
Alejandro
Hello there,
I have a function in a module that retrieves the system's username. Hereit is:
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
Now, this is a copy&paste from another example, I won't pretend that I
understand how this function works, but it does work. When I created this
workbook I added in cells several spreadsheets the formula =fosusername() and
indeed those cells showed my username. The problem I'm having is that now
when someone else opens the file it still shows my username.
I know that adding code for every single cell in every single spreadsheet
where I need the username will work (Range("XX")=fosusername()) but...is
there a way to "update" the value of this function, for example, when the
workbook is opened, so that I will not have to add code in all spreadsheets?
Thanks!
A.
I have a function in a module that retrieves the system's username. Hereit is:
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
Now, this is a copy&paste from another example, I won't pretend that I
understand how this function works, but it does work. When I created this
workbook I added in cells several spreadsheets the formula =fosusername() and
indeed those cells showed my username. The problem I'm having is that now
when someone else opens the file it still shows my username.
I know that adding code for every single cell in every single spreadsheet
where I need the username will work (Range("XX")=fosusername()) but...is
there a way to "update" the value of this function, for example, when the
workbook is opened, so that I will not have to add code in all spreadsheets?
Thanks!
A.