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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
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:
 

PritiOne

Active Member
Joined
Jun 2, 2004
Messages
357
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
 

PritiOne

Active Member
Joined
Jun 2, 2004
Messages
357

ADVERTISEMENT

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?
 

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
Activesheet.range("A1").value = Environ("UserName")

Cal
 

PritiOne

Active Member
Joined
Jun 2, 2004
Messages
357

ADVERTISEMENT

Can you help me tie both these sets of code together?
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Can you post the code that you have now?

Smitty

(Heya Cal!)
 

PritiOne

Active Member
Joined
Jun 2, 2004
Messages
357
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
 

Forum statistics

Threads
1,148,049
Messages
5,744,509
Members
423,881
Latest member
Nguyen Vu

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
Top