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.
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
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 email@example.com
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.