1. Design a login userform and display it on the open event of the workbook. Based on the credentials, you can control the access on the data
2. Instead of using login userform, you can get the system login user id and control the access on the data
Sub GetLoggedInUserName()
Dim strUserName As String
strUserName = Environ("Username")
Sheet1.Range("B4").Value = strUserName
End Sub
Sub Get_Username()
ActiveCell.Value = Application.UserName
End Sub
Function CurrentUser()
Dim objNetwork As Object
Dim strUserName As String
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
MsgBox strUserName
End Function
To use this code in your Excel file, follow below steps:
1. Open an Excel file
2. Press Alt+F11
3. Insert a Module (Insert>Module) from menu bar
4. Paste the code in the module
5. Now add a shape in Excel sheet
6. Give a name to the shape like ‘Get Logged In User Name’
7. Right click on the shape and select ‘Assign Macro…’
8. Select ‘GetLoggedInUserName’ from the list and click on ‘Ok’ button
9. Done, click on the shape to get the logged in user name
Hope you liked this article!!
Here are some other VBA codes which you can use in Excel:
We are currently offering our Excel VBA Course at discounted prices. This courses includes On Demand Videos, Practice Assignments, Q&A Support from our Experts. Also after successfully completion of the certification, will share the success with Certificate of Completion
This course is going to help you to excel your skills in Excel VBA with our real time case studies.
Lets get connected and start learning now. Click here to Enroll.
Here is another best rated Excel Charts and Graph Course from excelsirji. This courses also includes On Demand Videos, Practice Assignments, Q&A Support from our Experts.
This Course will enable you to become Excel Data Visualization Expert as it consists many charts preparation method which you will not find over the internet.
So Enroll now to become expert in Excel Data Visualization. Click here to Enroll.
Here are some other free Excel VBA Tools which may help you to increase productivity in your day to day jobs. Click here
Here we are coming with one more exciting post which can help you to solve very basic but very important problems while writing VBA codes.
VBA to Browse Outlook Folder Outlook is most commonly used emailing application used in the world. Many people spend their entire day on Outlook applications to read and respond to emails. To automate certain rule-based…
VBA Code to Filter Data in Excel Here is an easy reference code which filters data in the sheet. In the code, we have filtered the data in three steps. Step 1: Remove existing filter from…
Delta Symbol in Excel The Greek Capital Alphabet letter Delta (▲) and is commonly discussed topic in Excel. This is being used for various purposes i.e. changes in quantity, insert the symbol in excel etc….
VBA Code to Read Outlook Emails Reading emails from Outlook and capture them in Excel file is very common activity being performed in office environment. Doing this activity manually every time is quite boring and…
How to Change TEXT into DATE Format Microsoft Excel “DATEVALUE” is the very useful where dates are available as TEXT and need to convert them to proper DATE format. DATEVALUE function helps to convert the…
Does not work with Azure joined computers. Environ(“username”) appears to return blank
Hi,
Can you give an try to below code: