Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Update username

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Update username

Have you tried

fOSUserName = Environ("USERNAME")

HTH,
Barb Reinhardt

"Alejandro" wrote:

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Update username

You mean creating a new fOSUserName function using that code line instead of
my function? Whe would I use it?

I commented out my original function and created a new one in the same
module, but that didn't update the values of the cells in the spreadsheets.



"Barb Reinhardt" wrote:

Have you tried

fOSUserName = Environ("USERNAME")

HTH,
Barb Reinhardt

"Alejandro" wrote:

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Update username

On 17 Set, 00:45, Alejandro
wrote:
You mean creating a new fOSUserName function using that code line instead of
my function? Whe would I use it?

I commented out my original function and created a new one in the same
module, but that didn't update the values of the cells in the spreadsheets.



"Barb Reinhardt" wrote:
Have you tried


fOSUserName = Environ("USERNAME")


HTH,
Barb Reinhardt


"Alejandro" wrote:


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.- Nascondi testo citato


- Mostra testo citato -


Barb indication is correct and this work for me:

Function fOSUserName() As String
fOSUserName = Environ("USERNAME")
End Function

Eventually close the file and open that again.
Saluti
Eliano
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Update username


Function fOSUserName()
fOSUserName = Environ("UserName")
End Function

in any standard code module.

Use on a worksheet thus:
=fOSUserName()


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=135540



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Update username

Thank you!

However, your answer confirms what i stated initially (that in every
spreadsheet I'd have to enter the code line: Range("XX").value=fOSUserName()
) which is what I was trying to avoid since I have so many spreadsheets using
this function. From what you're saying it seems that there is no way to call
that function and update the value of fOSUserName when the workbook opens,
for example, instead of calling the function in every single worksheet.

"p45cal" wrote:


Function fOSUserName()
fOSUserName = Environ("UserName")
End Function

in any standard code module.

Use on a worksheet thus:
=fOSUserName()


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=135540


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Update username


Won't


Private Sub Workbook_Open()
Calculate
End Sub

in the ThisWorkbook code module do it?

I can't easily test where I am at the moment.


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=135540

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Update username

On 17 Set, 02:00, Alejandro
wrote:
Thank you!

However, your answer confirms what i stated initially (that in every
spreadsheet I'd have to enter the code line: Range("XX").value=fOSUserName()
) which is what I was trying to avoid since I have so many spreadsheets using
this function. From what you're saying it seems that there is no way to call
that function and update the value of fOSUserName when the workbook opens,
for example, instead of calling the function in every single worksheet.



"p45cal" wrote:

Function fOSUserName()
fOSUserName = Environ("UserName")
End Function


in any standard code module.


Use on a worksheet thus:
=fOSUserName()


--
p45cal


*p45cal*
------------------------------------------------------------------------
p45cal's Profile:http://www.thecodecage.com/forumz/member.php?userid=558
View this thread:http://www.thecodecage.com/forumz/sh....php?t=135540- Nascondi testo citato


- Mostra testo citato -


Probably I have not understood; however try this macro in the module:
ThisWorkbook

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Range("A1").Value = Environ("USERNAME")
End Sub

Regards
Eliano
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Update username

On 17 Set, 03:32, eliano wrote:
On 17 Set, 02:00, Alejandro
wrote:





Thank you!


However, your answer confirms what i stated initially (that in every
spreadsheet I'd have to enter the code line: Range("XX").value=fOSUserName()
) which is what I was trying to avoid since I have so many spreadsheets using
this function. From what you're saying it seems that there is no way to call
that function and update the value of fOSUserName when the workbook opens,
for example, instead of calling the function in every single worksheet.


"p45cal" wrote:


Function fOSUserName()
fOSUserName = Environ("UserName")
End Function


in any standard code module.


Use on a worksheet thus:
=fOSUserName()


--
p45cal


*p45cal*
------------------------------------------------------------------------
p45cal's Profile:http://www.thecodecage.com/forumz/member.php?userid=558
View this thread:http://www.thecodecage.com/forumz/sh...35540-Nascondi testo citato


- Mostra testo citato -


Probably I have not understood; however try this macro in the module:
ThisWorkbook

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Range("A1").Value = Environ("USERNAME")
End Sub

Regards
Eliano- Nascondi testo citato

- Mostra testo citato -


As names involved in Windows and Office could be two, try also:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Range("A1").Value = Application.UserName
End Sub

Saluti
Eliano
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
environ username vs. application username jatman Excel Programming 4 May 28th 09 08:40 AM
username robzrob Excel Worksheet Functions 2 May 4th 08 05:59 PM
Username Alvin Hansen[_2_] Excel Programming 3 September 25th 04 10:36 PM
username libby Excel Programming 8 April 25th 04 03:37 AM
Get NT Username Steven Pugh Excel Programming 7 February 20th 04 09:37 AM


All times are GMT +1. The time now is 06:22 PM.

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

About Us

"It's about Microsoft Excel"