Hey guys, welcome back. So in this video we're going to discuss the workbook, a new sheet event. So the workbook new sheet event runs whatever code you put in it whenever you insert in you sheet. So you can get out of course by opening your VBA editor double clicking on this workbook. And from this menu, you're going to select workbook and from this menu, we're going to select new sheet. So whatever code you put in, it will be run whenever you insert a new sheet.
So for example, I could put a message box you have inserted a new sheet. Okay, so now whenever we insert a new sheet, let's just insert a new sheet here. You can see here that the message box pops up, you have inserted a new sheet and actually this code runs after the sheet is inserted. So actually, the sheet is inserted first and then the code runs. Something else that we need to learn about is actually the S h parameter. Okay, and the SH parameter is basically a worksheet object, and it refers to the worksheet this just been inserted.
Okay? So something else that you can do is that you could give each new sheet inserted a number, okay, so for example, if we insert a new sheet in our case here, because it's going to be the fifth sheet in the workbook, it's going to be assigned the number five. So you can do this you could write sh dot name equals this workbook dot worksheets dot count. Okay, so now is going to be given the number five, or actually each sheet insert is going to be having a number that is going to be equal to the number of worksheets that would be available after inserting the new worksheet. So for example, let's insert a new sheet here. And series has been given the number five that's inserted.
Another one has been given a number six, because it's the sixth and let's insert a third one. It's going to give him the number seven because it's the seven okay? So this is the workbook new sheet event, I typically don't use that a lot. But if there is something in your business or something in your applications that you would require it for it's there, you know how to use it. Okay? And if you find something that this event would be really useful for and you liked it, please let me know about it.
Let me know about what application you use it for, you would be interested. So that's it for the workbook view sheet event. Thank you very much for watching this video. I'll see you on the next one.