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

VBA-Excel: Edit And Save an Existing Word Document

VBA-Excel: Save an Exist­ing Word Document

To Edit and save an exist­ing Microsoft Word Doc­u­ment using Microsoft Excel, you need to fol­low the steps below:

  • Cre­ate the object of Microsoft Word
  • 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.
  • Edit the Word Doc­u­ment using SelectionObject
  • Save the Word Document


Cre­ate the object of Microsoft Word

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

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

Edit the Word Doc­u­ment using SelectionObject

objSelection.Font.Size = “22”

objSelection.TypeText (“I am new here” & vbCrLf)

 

Save the Word Document

objDoc.Save

 

Com­plete Code:

Function FnEditAndSaveWordDoc()

   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.Font.Bold = True

   objSelection.Font.Size = "22"

   objSelection.TypeText ("I am new here" & vbCrLf)

   objDoc.Save

End Function

Word — Save

 


 

You may also like...

Leave a Reply

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

%d bloggers like this: