Hey guys, welcome back. So in this video we're going to discuss adding and saving workbooks using Excel VBA. So to add a new workbook, you just use the Add method with the workbook collection. So you write workbooks dot add. So if you run this macro, this actually opens a new workbook and this is similar to clicking on File here and then clicking on new or actually pressing CTRL and and on your keyboard. So just opening a blank new workbook.
You will notice also that the workbooks dot add method has an optional parameter, which is actually template. This template parameter allows you to open a workbook based on a template and you need to actually provide the location of the template that you need to open the new workbook based on so I'm going to actually Open a new workbook based on a template that I've got in my Templates folder. So I need to paste the location of that template, which is the default location for the templates folder, and it's called sales template and its extension is.xl tm, of course, your path could be different, you can actually check the path of your templates by going to File and then going to options. And then on the save menu here, you're going to have your default personal templates location. Okay, so back to our Visual Basic environment. So if I run this macro, we're going to open a new workbook based on a template, which is my sales template here.
So if we run that, you're going to see a new workbook has been opened based on a template that I had created. So I'm going to close that for now. Okay, so to actually save the changes to a workbook, you just use the workbook dot Save methods. So if you like this workbook save, this is actually going to save the changes to the workbook that contains this macro, which is called adding and saving workbooks. So if I run this macro, you're just saving the changes. And that is similar to pressing Ctrl S on your keyboard or going to File and then save.
Now I've actually activated the workbook that is school book, one that we've just opened, but we haven't saved yet. So this workbook has just been opened, as we've seen by using the workbook dot add method, but it has not been saved to a location yet, if used the workbook dot save method on that workbook. So now this is the workbook active. So for us the active workbook save method. If I run that, actually, this workbook is going to be saved and it's going to be saved to a location. So actually, we have Haven't been asked for the location as you could see here and the statement executed fine.
So where has that workbook been saved? Well, actually, it hasn't been saved to the default location for saving workbooks for Excel, which is usually the Documents folder. So here is the My Documents folder. And you can see here here is book one. So this is why it's not recommended to use the workbook dot save method to save newly opened workbooks or workbooks that have not been saved yet, because you don't get to determine the location for saving the workbook. And you also don't get to name it with a certain name, you know, let's say you don't want to name it with book one, you want to give it another name.
So the workbook save method does not give you the option. This is why it's also better to use the workbook Save as method, which actually we're going to see on the next video. So thanks guys for watching this video and I'll see you on the next one.