Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Format the Existing Table in a Word document

To Format the Existing Table in a Microsoft Word Document using Microsoft Excel, you need to follow the steps below:

  • Create the object of Microsoft Word
  • Open the already existing word document
  • Make the MS Word visible
  • Get the Table object
  • Edit  the data in table
  • Save the document

Create the object of Microsoft Word

Set objWord = CreateObject(“Word.Application”)

Open the already existing word document

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

Make the MS Word Visible

objWord.Visible = True

Get the Table object

Set objTable = objDoc.Tables(2)

Fill the data in table

objTable.Cell(1, 1).Range.Text = "I M NEW HERE

Save the Document

objDoc.Save

Complete Code:

Function FnFormatExistingTable()

   Dim objWord

   Dim objDoc

   Dim objRange

   Set objWord = CreateObject("Word.Application")

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

   objWord.Visible = True    

   Set objTable = objDoc.Tables(2)    

   For i = 1 To 3

      For j = 1 To 3

 objTable.Cell(i, j).Range.Text = "I M NEW HERE"

       Next

    Next   

End Function
Format the Existing Table in a Word document
Format the Existing Table in a Word document



Also Read:

  1. VBA-Excel: Open and Print the Word Document
  2. VBA-Excel: Working with Bookmarks- Insert text before Bookmark
  3. VBA-Excel: Change Font, Color, Weight of Table Data in the Word document
  4. VBA-Excel - Merger - Merge or Combine Many Word Documents Into One
  5. VBA-Excel: Create and Save the Word document
  6. VBA-Excel: Change Font, Color, Weight of Table Data in the Word document
  7. VBA-Excel: Create worksheets with Names in Specific Format/Pattern.
  8. VBA-Excel: Create a new Word Document