VB Code that reads computer log on

PritiOne

Active Member
Joined
Jun 2, 2004
Messages
357
I am trying to write a program that runs through Excel - using VB Code to read the computer user logon. Can anyone help me?

Thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How's this:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> GetPCName()
    <SPAN style="color:#00007F">Dim</SPAN> CurrentUserName  <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> PCName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
        
        CurrentUserName = Environ("USERNAME")
        PCName = Environ("COMPUTERNAME")
        
        MsgBox "PC User Name is: " & CurrentUserName, vbOKOnly + vbInformation, "PC User Name"
        MsgBox "PC Name is: " & PCName, vbOKOnly + vbInformation, "PC Name"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>

HTH,

Smitty
 
Upvote 0
This code will return the name of the current user. Would need more details on what you want to do with it, to give any further help.


MsgBox Environ("username")

Cal

PS: Darn, beat to the punch, at least it was smitty. :biggrin:
 
Upvote 0
I have an Excel sheet that refreshes data and need to only limit data presented to the user loged on the computer. The background application is called Noetix and I've linked the report ID into the code. The Noetix program asks for a user ID... instead of programming 165 users individually, I am trying to add code that will pick up the user name from the VPN ID.

Hope this makes sense!

Thanks!!!
P
 
Upvote 0
Also, if cell A1 on a sheet in the workbook needs to = the username of the person logged on the computer, how do I set A1 to = username?
 
Upvote 0
Here it is... In all it's glory :)

Sub GetPCName()
Dim CurrentUserName As String
Dim PCName As String

CurrentUserName = Environ("USERNAME")
PCName = Environ("COMPUTERNAME")

Sheets("Sheet1").Range("A1").Value = Environ("UserName")
MsgBox "PC User Name is: " & CurrentUserName, vbOKOnly + vbInformation, "PC User Name"
MsgBox "PC Name is: " & PCName, vbOKOnly + vbInformation, "PC Name"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top