Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Create and Save the Word document

For creating and saving the Microsoft Word Document using Microsoft Excel, you need to follow the steps below:

  • Create the object of Microsoft Word
  • Create a document object and add documents to it
  • Make the MS Word visible
  • Create a Selection object with the help of WordObject.
  • Use this Selection object to type the text into the WordDocument.
  • Save the document

 

Create the object of Microsoft Word

Set objWord = CreateObject(“Word.Application”)

Create a document object and add documents to it

Set objDoc = objWord.Documents.Add

Make the MS Word Visible

objWord.Visible = True

Create a Selection object with the help of WordObject.

Set objSelection = objWord.Selection

Use this Selection object to type the text into the WordDocument.

objSelection.TypeText ("This is my text in Word Document using Excel")

Save the Document

objDoc.SaveAs ("D:\MyFirstSave")

Complete Code:

Function FnWriteToWordDoc()

   Dim objWord

   Dim objDoc

   Dim objSelection

   Set objWord = CreateObject("Word.Application")

   Set objDoc = objWord.Documents.Add    

   objWord.Visible = True

   Set objSelection = objWord.Selection

   objSelection.TypeText ("Saving this file after this text")

   objDoc.SaveAs ("D:\MyFirstSave")

End Function 



Also Read:

  1. VBA-Excel: Find a word in a specific paragraph and change its formatting
  2. VBA-Excel: Working with Bookmarks- Insert text before Bookmark
  3. Excel-VBA : Send a Excel Workbook as Attachment in Mail From MS Outlook Using Excel
  4. VBA-Excel: Find a word in a specific paragraph and change its formatting
  5. VBA-Excel — AttachmentFetcher — Download all the Attachments from All the Mails of Specific Subject in Microsoft Outlook .