 In this video we're going to be looking at how you can execute a VBA macro in Excel based upon a change event that occurs just as you save the file. So what will happen is as you click the save button it'll identify that the button has been clicked but before it saves the file it will execute this line of code. So obviously anything that's executed in this code whether it's like changing values in the sheet they will be included when the file is saved. So to jump straight in we'll go I say we'll jump straight in and start doing the code. If you've seen our previous videos looking at change events some of this code will seem familiar to you but obviously that are going to be some changes to make it be specific to this particular event but let's say let's jump straight in and we're going to be coding this into the this workbook sheet. So there's a bit to type in this first part so like please bear with me but if you copy this you'll obviously have what you need. So private sub workbook and this will before save. So as we've previous videos when we've been looking at this as well it does seem quite self-explanatory obviously you might not know exactly what to write but hopefully just this line or this first part here of workbook before save sounds quite logical so it's easier to remember what you need to use it for your future. If you want to execute this just before this file is saved before save is quite a good descriptive term for how I'm using in here buy val and then save as ui should all be one word as boolean cancel as boolean and as we said before we don't need to concern yourself too much about obviously what this is saying in here um cancel obviously might have a part of the right so cancel and this one needs to be save as ui so there you go it doesn't matter too much about obviously what the details saying about making this video more complex than it needs to be but this is this is the code lines of code you need to be able to execute code but based on obviously an event before the file is saved. So all I'm going to do is just change the value in cell a1 so we refer to that by going sheets and brackets sheet one dot range and that's going to be a1 dot value equals and I'm going to say goodbye environment open brackets username and let's do one of those so again as if it's in the previous videos we've used this line of code in our examples basically what we're going to do is extract the username of the user access in the file and it'll just say goodbye to the username and we've got an exclamation mark at the end it's going to populate this into cell a1 so all we need to do to execute this is if you push the save button you can see that that has been included into the file for us and it's as simple as that obviously the real benefit of using this you could maybe use this in tandem with the close event we previously done but it's a really good beneficial way maybe even if you want to try and track changes what's happening in your workbook so every time someone saves the file you might want to obviously obtain the username that's made that save and you can start creating a log of those usernames and the timestamp so that you have full traceability of everyone who has saved that file so this is a really beneficial one as I said we've looked at other ones so open change during having the sheet open and even a chain or execute a change based on when the worksheet is closed but using this save one as I say can be very beneficial because it allows you to actually track changes every time a workbook is saved and from people's experience I have used that myself to help build out a change log so every time someone saves this file you can obviously one document that the change has been made and he made it but alternatively as well you can also track the people who are actively contributing to the file so if you're trying to get people to update something and they all say they are there are updating it by tracking obviously everyone who goes in here when they save you can have that document to say actually I know these people have and these people have it so just to give you one example but I'm sure you'll find many other examples or benefits of using this line of code in your excel work so if you enjoyed that video and it gave me the answer to a question you may be searching for please do give the video a like and it'll be greatly appreciated by myself if you have any questions about this or any other excel related questions please just drop myself a comment below the video and I will get back to you as soon as I can thank you very much for watching the video and we'll see you in the next one