use of WinUsername

craigexcel

Active Member
Joined
Jun 28, 2006
Messages
277
In looking for a way for VB to specifically recognize me as the person opening a workbook, I came across WinUsername. However, when the following is executed, a no (or a null?) value is returned.

Dim UserName As String
UserName = WinUsername
UserName = MsgBox("username is " & UserName, vbOKOnly)

I'm working on a company network. Is there another way for WinUsername to specifically identify me, or can you suggest alternate VB that would execute ONLY when I open the workbook? Thanks.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Here's one way:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> GetMyName()
    <SPAN style="color:#00007F">Dim</SPAN> CurrentUserName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
        CurrentUserName = Environ("Username")
    MsgBox CurrentUserName
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

You can add a simple IF statement to validate your name after that.

HTH,

Smitty
 

Forum statistics

Threads
1,136,514
Messages
5,676,293
Members
419,619
Latest member
jalme

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