How to save current user to...

albertc30

Well-known Member
Joined
May 7, 2012
Messages
1,091
Office Version
  1. 2019
Platform
  1. Windows
Hi all.

I am trying to save the current user to the sheet Customers when form is saved.

I have tried a few things but to no avail;

Code:
Sheets("Customers").Cells(i, "H").Value = tbncem.Text

'I have tried

Sheets("Customers").Cells(i, "H").Value = currentuser 'This actually saves the displayed word and not the current user, tried with "currentuser", still no luck.





Instead of the value H to be save from textbox, I want it to save the current username.

Now I could reference this to one sheet where it shows the username and just point the cell in question or, I can use the array I have of currentuser.


Could do with the same but to save date and time too.

As always, much appreciated for all your time.

Cheers.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try either
Code:
Environ$("username")
or
Code:
Application.UserName

depending on exactly what you need.
 
Upvote 0
Hello, Morning everyone.

Mark858;

Much appreciated for your time.

I got Daddy as for the username and I was lost for a few seconds, lol...

Then it hit me, that's my windows username, lol...

The username for the spreadsheet is loaded on a cell on sheet10. I was just hopping to copy that cell value in order to record wich user did do the changes.

I'm attaching the code that verifies the username and then places it to the relevant field.

Code:
Private Sub cmBtnLogin_Click()


    Dim rFoundPass As Range
  
    'Sheets("UsersHide").Unprotect Password:="********"
  
  With Sheets("UsersHide").Range("UserNames")
    Set rFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
      :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      False)
  End With
  
  If rFoundPass Is Nothing Then
     SomethingWrong
      Exit Sub
  End If
  
  If Sheets("UsersHide").Cells(rFoundPass.Row, 2) <> txtBoxPassword Then
     SomethingWrong
      Exit Sub
  End If
  
  Sheets("Invoice").Unprotect Password:="*****"
  Sheets("Invoice").Range("CurrentUser") = txtBoxUserName     'Current username using the sheet is placed on the range CurrentUser
  Sheets("Invoice").Protect Password:="arrudac"
  
  'Sheets("UsersHide").Protect Password:="*******"
  
  Unload Me
  Application.Visible = True


End Sub

Again and as always, any help is much appreciated.

Thanks for your time.

Cheers
 
Upvote 0
I am not sure exactly what you require here, by what you have written all you want to do is refer to your named range CurrentUser and add a timestamp.

I am sure that is not what you need but if it is then it is just...

Code:
Sheets("Customers").Cells(i, "H").Value = Sheets("Invoice").Range("CurrentUser").Value & " " & Format(Now, "dd/mm/yyyy hh:mm")

Btw, I hope that is not your actual password you have left in the code.
 
Upvote 0
Hi mate.

It worked a treat.

The password is only temporary as it's too easy, lol...

Much appreciated for your time and help.

Chers
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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