VBA – Opening and closing Word from Excel

Do you know that VBA can take over all the control over different MS Office applications?

This is a simple example how you can open and close a Word application from Excel. In order to do this, you may use the following simple code:

The code does the following three things:

1. The first line declares the public variable “Vitosh” as a New Word.Application. Thus this public variable can be called from both the modules just by mentioning it.

2. The Sub VitoshAcademy1 is only one line, telling to excel to call a new word application and to make it visible.

3. The Sub VitoshAcademy2 Quits the calles application and sets it to nothing. Before doing it, it asks Word not to display Alerts.

The file with this code is here. In order to see it, you should enable macros.

In order to make sure, that the macro runs smoothly, you should add a reference “Microsoft Word 14.0 Object Library”. (or any other version of Word, corresponding to your current version). In order to do it, you should open the VBA window>References>Select from the list =>” Microsoft Word 14.0 Object Library” > Click Add.


This will add this library to your VBA.


VBA Developer