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 All Content

VBA-Excel: For­mat already writ­ten text in a word doc­u­ment – For­mat All Content

 

To For­mat already writ­ten text in a word doc­u­ment – For­mat All Con­tent 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
  • Cre­ate a Selec­tion object with the help of WordObject.
  • Select the Whole con­tent in the word document
  • 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

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

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

Select the Whole con­tent in the word document

objSelection.WholeStory

Do the formatting

objSelection.Font.Name = “Algerian”

objSelection.Font.Bold = True

objSelection.Font.Color = RGB(12, 200, 0)

Save the Word Document

objDoc.Save

Close the word document

obj­Word.Quit

 

Com­plete Code:

Function FnFormatAllContent()

   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.WholeStory

   objSelection.Font.Name = "Algerian"

   objSelection.Font.Bold = True

   objSelection.Font.Color = RGB(12, 200, 0)

   objDoc.Save

   objWord.Quit

End Function
FormatAllContent

For­matAll­Con­tent

 

You may also like...

Leave a Reply

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

%d bloggers like this: