Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Appending Text to Existing Word Document - at Beginning

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

  • 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.
  • Append the text in  the Word Document using SelectionObject

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

Append the text in  the Word Document using SelectionObject

objSelection.TypeText ("Yeahhh..I will be at the Beginning of the Document. J" & vbCrLf)

Complete Code:

Function FnAppendAtBeginning()

   Dim objWord

   Dim objDoc

   Dim objSelection

   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.Font.Size = "25"
   objSelection.Font.Color = RGB(124, 123, 0)    

   objSelection.TypeText ("Yeahhh..I will be at the Beginning of the Document. :)" &  vbCrLf)

End Function
MS word - append Text at beginning
MS word - append Text at beginning 



Also Read:

  1. VBA-Excel: Modified Consolidator – Merge or Combine Multiple Excel Files Into One Where Columns Are Not In Order
  2. VBA-Excel - Merger - Merge or Combine Many Word Documents Into One
  3. VBA-Excel: Appending Text to an Existing Word Document - at the End
  4. VBA-Excel - Merger - Merge or Combine Many Word Documents Into One
  5. Excel-VBA : Send Unique Images Embedded to Mail Body, With Every Mail From MS Outlook using Excel.