Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Working with Bookmarks- Insert text After Bookmark

For inserting the text after the Bookmark in an existing Microsoft Word Document using Microsoft Excel, you need to follow the steps below:

Add a Bookmark “IMBOOKMARK” with name “bookmark_1

  • Create the object of Microsoft Word
  • Create Doc object using MS word object, Open the existing word document by providing the complete path
  • Make the MS Word visible
  • Get the range object for the bookmark
  • Insert the text after the bookmark
  • Save the word document
  • Close the word document


Create the object of Microsoft Word

Set objWord = CreateObject(“Word.Application”)

Create Doc object 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

Get the range object for the bookmark

Set objRange = objDoc.Bookmarks("bookmark_1").Range

Insert the text AFTER the bookmark

objRange.InsertAfter ("..........I will be added AFTER bookmark")

Save the Word Document

objDoc.Save

Close the word document

objWord.Quit

Complete Code:

Function FnBookMarkInsertAfter()

   Dim objWord

   Dim objDoc

   Dim objRange

   Set objWord = CreateObject("Word.Application")

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

   objWord.Visible = True

    Set objRange = objDoc.Bookmarks("bookmark_1").Range

    objRange.InsertAfter ("..........I will be added AFTER bookmark")

End Function
Insert Text After Bookmark
Insert Text After Bookmark



Also Read:

  1. VBA-Excel: Maximize, Minimize and Restore Internet Explorer (IE) using Microsoft Excel.
  2. VBA-Excel: Create and Save the Word document
  3. VBA-Excel: Login To Already Opened GMAIL In An Internet Explorer (IE)
  4. VBA-Excel: Writing Text to Word document
  5. Excel-VBA : Send a Simple Mail From MS Outlook Using Excel
  6. VBA-Excel: Create a new Word Document
  7. VBA-Excel: Add/Insert a Image/Picture in Word Document
  8. Send Mail With Multiple Different Attachments From MS Outlook using Excel.