Launch Word file from Excel VBA

In this article, we will create a macro to open word document.

To open a word document, we will specify full path of the document in the text box on main sheet. After specifying the full path, click on the “Submit” button to execute the macro.

 

ArrowMainSheet

 

Code explanation

Dim WDApp As Word.Application

Above code is used to declare object of the word application.

Set WDApp = CreateObject("word.Application")

Above code is used to create a new object of the word application. Word application will start running, but by default, it will not be visible.

WDApp.Visible = True

Above code is used to make the word application window visible.

Set WDDoc = WDApp.Documents.Open(FileName)

Above code is used to open the word document.

Set WDDoc = Nothing

Set WDApp = Nothing

Above code is used to release any memory occupied by the object.

 

Please follow below for the code


Sub OpeningWordFile()

'Declaring variables
Dim FileName As String
Dim WDApp As Word.Application
Dim WDDoc As Word.Document

'Getting the file name from the text box
FileName = Sheets("Main").TextBox1.Value

'Creating object of the word application
Set WDApp = CreateObject("word.Application")

'Making visible the word application
WDApp.Visible = True

'Opening the required word document
Set WDDoc = WDApp.Documents.Open(FileName)

'Release the memory used by object variable
Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

 

If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.

We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube