Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Format already written text in a word document – Format Paragraphs

To Format already written text in a word document – Format Paragraphs  - Microsoft Word Document using Microsoft Excel, you need to follow the steps below:

  • 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 paragraphs count
  • Get the paragraph object using Paragraphs.Range
  • Do the formatting
  • 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 paragraphs count

objDoc.Paragraphs.Count

Get the paragraph object using Paragraphs.Range

objDoc.Paragraphs(i).Range

Do the formatting

objParagraph.Font.Name = "Times New Roman"

Save the Word Document

objDoc.Save

Close the word document

objWord.Quit

Complete Code:

Function FnFormatParagraph()

   Dim objWord

   Dim objDoc

   Dim intParaCount

   Dim objParagraph

   Set objWord = CreateObject("Word.Application")

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

   objWord.Visible = True 

   intParaCount = objDoc.Paragraphs.Count

   'MsgBox intParaCount

   For i = 1 To intParaCount

     Set objParagraph = objDoc.Paragraphs(i).Range       

 objParagraph.Font.Name = "Times New Roman"

 objParagraph.Font.Size = 5 + (i * 8)

 objParagraph.Font.Bold = True

 objParagraph.Font.Color = RGB((i * 100), (i * 50), 0)

   Next

   objDoc.Save

   objWord.Quit

End Function
Format paragraphs
Format paragraphs



Also Read:

  1. VBA-Excel - Merger - Merge or Combine Many Word Documents Into One
  2. VBA-Excel: Create worksheets with Names in Specific Format/Pattern.
  3. VBA-Excel: Convert Numbers (Rupees) into Words OR Text - Updated Till 1000000 Crore With Decimal Numbers
  4. VBA-Excel: Working with Microsoft Word
  5. VBA-Excel: Change Font, Color, Weight of Table Data in the Word document