The different tools offered by the Microsoft Office suite allow us not only to create documents, but also to create functions. Of course this is for those programmers who know Visual Basic VBA Applications. But we are going to make it easy for you and in this article we are going to teach you how to close Word from a code or VBA Script – easy and fast.
But first we will reveal the question about what Visual Basic Applications are and this is nothing more than an application integrated into the Microsoft Office package.
This allows programming in the sheets of any document, be it Word, Excel, PowerPoint, Access, and since it cannot be compiled, it becomes a macro and is distributed by simply copying the document.
Although this is an activity that is widely used by programmers, it does not prevent any mortal from learning to create functions using VBA Scripts. And we will give ourselves the task of teaching it to you in a quick and simple way. Since some terms may seem confusing and somewhat intimidating, such as when you try to convert an OpenOffice document to Word.
How to close Word from a code or VBA Script
One of its main uses has to do with the automation of repetitive or frequently used tasks, such as this one, of opening or closing a document created in Word.
Here are the steps you must apply to be able to close Word from a code or VBA Script. And to start we enter the application from the desktop or wherever we have it saved.
The next step is important because you must have the Developer tab in the main menu, if this tab is not showing, you must do the following. Hover over the Microsoft Office icon and click. This action will show a box with different options and you must go to the bottom of it and select Word Options.
Now a box will be displayed and on the left side of it you must choose the Most frequent option and on the right side in the Main options section for working with Word.
You are going to look for the option Show Developer tab in the Options ribbon and when locating it you must click on the checkbox that is on its left side to select it.
Steps to close Word from a code or VBA Script- Easy and fast
Once you have the programmer tab on the ribbon, you can continue with the instructions that will allow you to close Word from a code or VBA Script.
The next step is to go to the main menu and select the Developer tab. Then in the Code section on the left side, select the visual Basic option.
The next step will be to type or paste the following code at the end of the line, Set objWord = CreateObject(“Word.Application”) Set objDoc = objWord.Documents.Close(“c:scriptstest.doc’) objWord.Quit the next step will be to go to the upper left corner and click on the Microsoft Office icon.
Then you must choose the Save option and you are going to do it with the following name test.doc, this with the VBA code that you will use to close the Word application.
You can see how easy and fast it is to perform programming tasks. And use the Basic programming language which is very similar to other office packages such as OpenOffice and StarBasic.
And with this learning about programming language we have finished with the tutorial, but you may be interested in knowing more about the way programming source codes are inserted into a document. And so you can learn more about this very little explored point of the Word program.