Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

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

To append the text at the begin­ning of the already exist­ing Microsoft Word Doc­u­ment using Microsoft Excel, you need to fol­low the steps below:

  • Cre­ate the object of Microsoft Word
  • Using MS word object, Open the exist­ing word doc­u­ment by pro­vid­ing the com­plete path
  • Make the MS Word visible
  • Cre­ate a Selec­tion object with the help of WordObject.
  • Append the text in  the Word Doc­u­ment using SelectionObject

 

Cre­ate the object of Microsoft Word

Set obj­Word = CreateObject(“Word.Application”)

Using MS word object, Open the exist­ing word doc­u­ment by pro­vid­ing the com­plete path

Set obj­Doc = objWord.Documents.Open(“D:\OpenMe.docx”)

Make the MS Word Visible

objWord.Visible = True

Cre­ate a Selec­tion object with the help of WordObject.

Set objS­e­lec­tion = objWord.Selection

Append the text in  the Word Doc­u­ment using SelectionObject

objSelection.TypeText (“Yeahhh..I will be at the Begin­ning of the Doc­u­ment. J” & vbCrLf)

Com­plete 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 

 

You may also like...

Leave a Reply

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

%d bloggers like this: