N00b needs help with usernames

yourfriendkyle

New Member
Joined
Aug 3, 2010
Messages
3
Hi,

I've been scanning the web for a solution to my problem and what help I have found I could do with it expanding a little.

Right, I'm after inserting the current logged on user's name into an excel cell.
It may sound simple enough to some of you pro's but if you could help with the instructions as I'm new to visual basic, etc.

Just some background notes; different users may be using the workbook to create a new tab from a standard template to fill in. Is a simple way of inserting the username going to work, or is it best to be insert it in a specific cell for whatever tab the users creates and prints??

Any help's greatly appreciated.

Thanks.
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Environ("USERNAME")

Gives you the users Windows Log on.

As for the rest of the question, you really need to decide what you need to do.

I wold suggest though that using an event initiated macro would be your best bet, so that when a user adds a sheet the code is run and places the user name in the relevant cell.

i.e. something like

Code:
Public Sub Workbook_NewSheet(ByVal Sh As Object)

Range("A1").Value = Environ("USERNAME")

End Sub
 
Upvote 0
@wesimmo
Yes thats great. I think the way you suggested would work the best as it will be a new tab whenever someone wants to use and print (it's like a form).

As far as implementing it, would you be able to break it down into steps, i.e. say im in my excel book, id open up Visual Basic and put the code in and save, is that right? Also is where it says "range a1", where I put the custom cell to give the name or is this like creating a custom function?

Thanks again.
 
Upvote 0
No probs mate.

I'd put it in This Workbook, open VBA Editor then on the left hand side in Project Explorer, right click "This Workbook" and then View Code (this is all from memory as i dont have excel on this computer).

Paste the code in, as you say edit the A1 bit to refer to where you want the user name to appear and job is a good 'un.
 
Upvote 0
Thats great. Thanks so much for the help. I think I was going wrong by saving the code to the tab instead of the workbook.

Cheers again :)
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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