Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Appending Text to an Existing Word Document - at the End

To append the text at the end of the Microsoft Word Document using Microsoft Excel, you need to follow the steps below:

  • Declare END_OF_STORY and MOVE_SELECTION as variables
  • Assign MOVE_SELECTION =0 and END_OF_STORY = 6
  • Create the object of Microsoft Word
  • Using MS word object, Open the existing word document by providing the complete path
  • Make the MS Word visible
  • Create a Selection object with the help of WordObject.
  • Move the Selection to the end of the document.
  • Append the text in  the Word Document using SelectionObject


Declare END_OF_STORY and MOVE_SELECTION as variables

Dim END_OF_STORY

Dim MOVE_SELECTION

Assign MOVE_SELECTION =0 and END_OF_STORY = 6

END_OF_STORY = 6

MOVE_SELECTION = 0

Create the object of Microsoft Word

Set objWord = CreateObject(“Word.Application”)

Using MS word object, Open the existing word document by providing the complete path

Set objDoc = objWord.Documents.Open("D:\OpenMe.docx")

Make the MS Word Visible

objWord.Visible = True

Create a Selection object with the help of WordObject.

Set objSelection = objWord.Selection

Move the Selection to the end of the document.

objSelection.EndKey END_OF_STORY, MOVE_SELECTION

Append the text in  the Word Document using SelectionObject

objSelection.TypeText ("Whattt..I am at the End of the Document. Not Fair :(" & vbCrLf)

Complete Code:

Function FnAppendAtEND()

   Dim objWord

   Dim objDoc

   Dim objSelection

  Dim END_OF_STORY

    Dim MOVE_SELECTION    

   END_OF_STORY = 6

    MOVE_SELECTION = 0    

  Set objWord = CreateObject("Word.Application")    

  Set objDoc = objWord.Documents.Open("D:\OpenMe.docx")

  objWord.Visible = True

  Set objSelection = objWord.Selection

  objSelection.Font.Bold = True    

  objSelection.EndKey END_OF_STORY, MOVE_SELECTION    

  objSelection.Font.Size = "25"

  objSelection.Font.Color = RGB(12, 200, 0)

  objSelection.TypeText ("Whattt..I am at the End of the Document. Not Fair :(" & vbCrLf)            

End Function
MS Word -Append Text at the End
MS Word -Append Text at the End



Also Read:

  1. VBA-Excel: Get ALL The Opened Internet Explorer (IE) using Microsoft Excel
  2. VBA-Excel: Format the Existing Table in a Word document
  3. VBA-Excel: Read Data from XML File
  4. VBA-Excel: Add Table and fill data to the Word document
  5. VBA-Excel: Working with Bookmarks- Insert text After Bookmark
  6. VBA-Excel: Login To Already Opened GMAIL In An Internet Explorer (IE)
  7. VBA-Excel: Change Font, Color, Weight of Table Data in the Word document
  8. VBA-Excel: Add/Insert a Image/Picture in Word Document