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

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

To For­mat already writ­ten text in a word doc­u­ment – For­mat Para­graphs  — Microsoft Word Doc­u­ment using Microsoft Excel, you need to fol­low the steps below:

  • Cre­ate the object of Microsoft Word
  • Cre­ate Doc object 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
  • Get the para­graphs count
  • Get the para­graph object using Paragraphs.Range
  • Do the formatting
  • Save the word document
  • Close the word document


Cre­ate the object of Microsoft Word

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

Cre­ate Doc object 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

Get the para­graphs count

objDoc.Paragraphs.Count

Get the para­graph 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

obj­Word.Quit

 

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

For­mat paragraphs

 

You may also like...

2 Responses

  1. Vijay says:

    It’s really Good …Thank you soo much !!
    Keep up good Work.
    Thanks,
    Vijay D

Leave a Reply

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

%d bloggers like this: