#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default User Name

I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default User Name

Environ("UserName")

You could create a UDF to return that value and call that from the
worksheet.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"RebekahK20_pontiac via OfficeKB.com" <u36479@uwe wrote in message
news:77147ce879aef@uwe...
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default User Name

Hi

MsgBox (Application.UserName)

should do the trick

S


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default User Name

You need this in order to use the Environ function:

Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function





--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"Bob Phillips" wrote:

Environ("UserName")

You could create a UDF to return that value and call that from the
worksheet.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"RebekahK20_pontiac via OfficeKB.com" <u36479@uwe wrote in message
news:77147ce879aef@uwe...
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default User Name

Forgive my ignorance, but now I'm getting an undefined variable?
And this goes in under the workbook, but how do i tell it where to put the
username?

Michael wrote:
You need this in order to use the Environ function:

Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function

Environ("UserName")

[quoted text clipped - 3 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via http://www.officekb.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default User Name

The UserName variable is undefined. Code the UDF this way:

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

and, place it inside a code module. Then, in your worksheet, use it just
like a built-in function. For example, in A1, enter the formula:

=UserNameWindows()




--
Hope that helps.

Vergel Adriano


"RebekahK20_pontiac via OfficeKB.com" wrote:

Forgive my ignorance, but now I'm getting an undefined variable?
And this goes in under the workbook, but how do i tell it where to put the
username?

Michael wrote:
You need this in order to use the Environ function:

Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function

Environ("UserName")

[quoted text clipped - 3 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via http://www.officekb.com


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default User Name

Thanks - but I'm still getting the error #Name? in the cell in Excel

I found a reference to the following code:


Public Function GetUsername() As String

On Error Resume Next


Dim objScript As Object
Set objScript = CreateObject("WScript.NetWork")
If Not objScript Is Nothing Then
GetUsername = objScript.UserName
End If
Set objScript = Nothing


End Function
Public Function GetUserDisplayName() As String
'--------------------8<----------------------
Set oADSystemInfo = CreateObject("ADSystemInfo")
' get user object
Set oADsUser = GetObject("LDAP://" & oADSystemInfo.UserName)
' get full name of the current user
GetUserDisplayName = oADsUser.displayname
'--------------------8<----------------------
End Function


I get an error when it gets to Set oADSystemInfo

Any clue? Some odd reason I think I'm making this much more difficult than it
should be.

Vergel Adriano wrote:
The UserName variable is undefined. Code the UDF this way:

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

and, place it inside a code module. Then, in your worksheet, use it just
like a built-in function. For example, in A1, enter the formula:

=UserNameWindows()

Forgive my ignorance, but now I'm getting an undefined variable?
And this goes in under the workbook, but how do i tell it where to put the

[quoted text clipped - 11 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default User Name

Are you sure you placed this function in a code module?

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

Then, in excel you use it like this:

=UserNameWindows()

Note the open and close parentheses at the end...if you don't include those,
you'll get the #NAME? error.


--
Hope that helps.

Vergel Adriano


"RebekahK20_pontiac via OfficeKB.com" wrote:

Thanks - but I'm still getting the error #Name? in the cell in Excel

I found a reference to the following code:


Public Function GetUsername() As String

On Error Resume Next


Dim objScript As Object
Set objScript = CreateObject("WScript.NetWork")
If Not objScript Is Nothing Then
GetUsername = objScript.UserName
End If
Set objScript = Nothing


End Function
Public Function GetUserDisplayName() As String
'--------------------8<----------------------
Set oADSystemInfo = CreateObject("ADSystemInfo")
' get user object
Set oADsUser = GetObject("LDAP://" & oADSystemInfo.UserName)
' get full name of the current user
GetUserDisplayName = oADsUser.displayname
'--------------------8<----------------------
End Function


I get an error when it gets to Set oADSystemInfo

Any clue? Some odd reason I think I'm making this much more difficult than it
should be.

Vergel Adriano wrote:
The UserName variable is undefined. Code the UDF this way:

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

and, place it inside a code module. Then, in your worksheet, use it just
like a built-in function. For example, in A1, enter the formula:

=UserNameWindows()

Forgive my ignorance, but now I'm getting an undefined variable?
And this goes in under the workbook, but how do i tell it where to put the

[quoted text clipped - 11 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default User Name

If you want to display the Username in a cell you can do the following

Function UserNameWindows() As String
UserName = Environ("USERNAME")
Range("A1").Value = UserName

End Function

And all you have to do is execute the formula

--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"RebekahK20_pontiac via OfficeKB.com" wrote:

Thanks - but I'm still getting the error #Name? in the cell in Excel

I found a reference to the following code:


Public Function GetUsername() As String

On Error Resume Next


Dim objScript As Object
Set objScript = CreateObject("WScript.NetWork")
If Not objScript Is Nothing Then
GetUsername = objScript.UserName
End If
Set objScript = Nothing


End Function
Public Function GetUserDisplayName() As String
'--------------------8<----------------------
Set oADSystemInfo = CreateObject("ADSystemInfo")
' get user object
Set oADsUser = GetObject("LDAP://" & oADSystemInfo.UserName)
' get full name of the current user
GetUserDisplayName = oADsUser.displayname
'--------------------8<----------------------
End Function


I get an error when it gets to Set oADSystemInfo

Any clue? Some odd reason I think I'm making this much more difficult than it
should be.

Vergel Adriano wrote:
The UserName variable is undefined. Code the UDF this way:

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

and, place it inside a code module. Then, in your worksheet, use it just
like a built-in function. For example, in A1, enter the formula:

=UserNameWindows()

Forgive my ignorance, but now I'm getting an undefined variable?
And this goes in under the workbook, but how do i tell it where to put the

[quoted text clipped - 11 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default User Name

Thank You Thank You!!

I had been putting it into a code module, but it didn't work till I created a
2nd module.

Do I need to create individual modules for most functions?

Thank you for all of your help - this could actully be fun...

Vergel Adriano wrote:
Are you sure you placed this function in a code module?

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

Then, in excel you use it like this:

=UserNameWindows()

Note the open and close parentheses at the end...if you don't include those,
you'll get the #NAME? error.

Thanks - but I'm still getting the error #Name? in the cell in Excel

[quoted text clipped - 45 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default User Name

No, you shouldn't have to put them in separate modules...


--
Hope that helps.

Vergel Adriano


"RebekahK20_pontiac via OfficeKB.com" wrote:

Thank You Thank You!!

I had been putting it into a code module, but it didn't work till I created a
2nd module.

Do I need to create individual modules for most functions?

Thank you for all of your help - this could actully be fun...

Vergel Adriano wrote:
Are you sure you placed this function in a code module?

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

Then, in excel you use it like this:

=UserNameWindows()

Note the open and close parentheses at the end...if you don't include those,
you'll get the #NAME? error.

Thanks - but I'm still getting the error #Name? in the cell in Excel

[quoted text clipped - 45 lines]
I've seen some posts on how to obtain the computer name, but how can i get
the username to display instead and tie it to a specific cell?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200708/1


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default User Name

No.

Event code and Functions/macros are stored in different types of modules.

Event code in sheet or workbook...............functions and macros in regular
modules.

You can have many functions/macros in one module.

No more than one type of event code in a sheet or workbook, however.

i.e. You can't have two worksheet_change events in one sheet module.


Gord Dibben MS Excel MVP


On Wed, 22 Aug 2007 18:26:15 GMT, "RebekahK20_pontiac via OfficeKB.com"
<u36479@uwe wrote:

Do I need to create individual modules for most functions?


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
Automatically add a textbox to a user form based on user requireme Brite Excel Programming 4 April 7th 07 11:37 PM
User form ComboBox Items: Remember user entries? [email protected] Excel Programming 0 March 29th 07 06:41 PM
How to: User Form to assign a user defined range to a macro variab TrevTrav Excel Programming 1 March 22nd 05 07:57 PM
User Defined Functions - Help Text - Make it Easy for the User Andibevan[_2_] Excel Programming 4 March 17th 05 09:51 AM
How to: Make user click End User License Agreement acceptance jasonsweeney[_21_] Excel Programming 7 January 30th 04 01:41 AM


All times are GMT +1. The time now is 04:01 PM.

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

About Us

"It's about Microsoft Excel"