In this video, we're going to discuss the workbook close method. And the workbook close method allows us to close a workbook. So I've got a workbook here called closing workbooks. And if I want to close this workbook, I'd write active workbook close, I could also write this workbook close. And I could also write the name of the workbook using the workbooks collection. So I'd write workbooks, closing workbooks, close.
So if I run this code, you can see here that I get prompted on whether I would like to save my changes or not, which is actually the normal thing that happens when you make changes to a workbook and you're trying to close it, Excel will prompt you on whether you'd like to save the changes or not. I'm not going to save the changes for now. I'm going to press Cancel. And actually, the workbook close method has some parameters. Actually, we're only going to discuss the Save Changes in the file name because the route workbook parameter is actually an obsolete parameter that was being used until office 97 only. So we're only going to discuss the Save changes and the file name.
The Save Changes parameter allows you to either save the changes that you've done or not. So if you put that equals true, then the changes are going to be saved and you're not going to be prompted on whether you'd like to save the changes or not. So the workbook will be closed and your changes will be saved. If you put it equal to false, then the workbook will be closed without saving the changes. Okay. And there is another one here that is called the filename and this allows you to basically save the workbook to a certain destination.
So I'm going to save it actually to a test folder on my desktop. Okay, so there's a folder on my desktop called test folder. I'm going to save it with the name test dot XLS m, on that folder, so you need to actually run Write the complete path and include as well the name of the file that you need to save it with. Okay, so this acts as a save as basically you're saving it as a certain name in a certain location. And actually, in order to do that, of course, you need to have the Save Changes to be equal to true, right because you cannot ask Excel to not save the changes and at the same time, save it in a certain location. So if you run this macro, what's going to happen is that this Excel file will be closed and where it's going to be also saved as this name in the location that I've specified.
So to run that we can see here that the Excel file has been closed. And if I go here to my test folder, you can see here that there is the test file that I saved. Okay, guys, so I've actually reopened my file now, and I would just like to tell you that doing a safe Using the close method is not the recommended way of doing it. It is actually more recommended that you would do it using the dot Save as method, which we're going to discuss in an upcoming lesson. So thank you guys for watching this video and I'll see you on the next one.