• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to update a cell with a value before User closes or saves the workbook?

inddon

Member
Hello There,

I would like to update a cell in a specific worksheet with the userid value. This should occur when the user saves or closes and saves the workbook

Below code I have written, and the save popup keeps coming up.

Could you please advice how my requirement could be achieved?


Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
   Set ws = Worksheets("Main Menu")
   'UserId is a global variable  
   ws.Range("R3").Value = UserId
  Cancel = True
End Sub



Thanks & regards,
Don
 
I would change this line of code
Code:
ws.Range("R3").Value = UserId
to
Code:
ws.Range("R3").Value = Environ("UserName")
 
I would change this line of code
Code:
ws.Range("R3").Value = UserId
to
Code:
ws.Range("R3").Value = Environ("UserName")


Hi Alan,

Thank you for your response.

I am retrieving the concatenated value of the email id from the outlook, which works fine.

I am looking for the following to achieve:
1. When the User clicks on 'Save,'it should assign this value to a cell and then the workbook should get saved.

Right now, with my above code, I close the application and it asks for 'Save', Don't save and Cancel. When I click Save, this popup keeps on appearing.

Could you let me know how can I acheive the above point 1?

Thanks
Don
 
Don
Sorry I missed that. Perhaps adding this to your code at the beginning.

Code:
Application.DisplayAlerts = False
 
Back
Top