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

VBA-Excel: Add/Insert multiple Images/Pictures from a folder in Word Document

To Add or Insert Mul­ti­ple Images or Pic­tures in Microsoft Word Doc­u­ment using Microsoft Excel, you need to fol­low the steps below:

  • Declare END_OF_STORY and MOVE_SELECTION as variables
  • Assign MOVE_SELECTION =0 and END_OF_STORY = 6
  • Cre­ate the object of Microsoft Word
  • Cre­ate the object of FileSys­te­mOb­ject
  • Cre­ate Folder object using FileSys­te­mOb­ject and Get­Folder method
  • 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.
  • Access Folder files using Folder object
  • Get the image paths from the folder
  • Insert image in the word doc­u­ments using AddPic­ture()
  • Insert a page break after every image


Declare END_OF_STORY and MOVE_SELECTION as variables

Dim END_OF_STORY

Dim MOVE_SELECTION

Assign MOVE_SELECTION =0 and END_OF_STORY = 6

END_OF_STORY = 6

MOVE_SELECTION = 0

Cre­ate the object of Microsoft Word

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

Cre­ate the object of FileSystemObject

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

Cre­ate Folder object using FileSys­te­mOb­ject and Get­Folder (link) method

Set obj­Folder = objFSO.GetFolder(strFolderPath)

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

Access Folder files using Folder object

objFolder.Files

Get the image paths from the folder

Img­Path = Img.Path

Insert image in the word doc­u­ments using AddPicture()

objSelection.InlineShapes.AddPicture (Img­Path)

Insert a page break after every image

objSelection.insertbreak

 

Com­plete Code:

 

Function FnInsertMultipleImages(strFolderPath)

   Dim objWord

   Dim objDoc

   Dim objSelection

   Dim objShapes

   Dim objFSO

   Dim objFolder

   Set objWord = CreateObject("Word.Application")

   Set objFSO = CreateObject("Scripting.FileSystemObject")    

   Set objFolder = objFSO.GetFolder(strFolderPath)

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

   objWord.Visible = True

   Set objSelection = objWord.Selection

   For Each Img In objFolder.Files

     ImgPath = Img.Path

        objSelection.InlineShapes.AddPicture (ImgPath)

 objSelection.insertbreak

   Next

End Function
Word-Insert-Image-Multiple

Word-Insert-Image-Multiple

 

 

You may also like...

8 Responses

  1. Zloty potok says:

    You need to be a part of a con­test for one of the most use­ful web­sites online.
    I’m going to highly rec­om­mend this site!

  2. Michael Grandal says:

    Hi. Can the code be mod­i­fied to insert mul­ti­ple objects (Cre­ate from file, dis­play as icons) into an word doc­u­ment? Can this be done with­out involv­ing Excel?

    thanks
    Michael

  3. Shyam says:

    My excel sheet has 10 rows, and i have a folder called “Input” which has 10 files of different/unknown file types. my job is to insert those 10 files in 10 appro­pri­ate rows as objects. Usu­ally i insert one file by another one by going Insert->Object->Create from file.
    Its time con­sum­ing and ide­ally tough espe­cially when i am hav­ing 100+ files to insert as spec­i­fied above. It would be great if any­one posts the answer. Kindly help and save me.

  4. prakaskh says:

    Lit­tle con­fused. I would like to know the codes like, “sub insertpic().….…..end sub”.. This arti­cle started only with “Function.….End Fuc­tion”.. I am not aware of the remain­ing things. Could you please pro­vide the entire pro­gram.. Sorry. I am new into this field.

    • Sumit Jain says:

      you can just call the func­tion inside your sub()

      Exam­ple:

      Sub insertScript()
      FnInsertMultipleImages(“provide the path of the folder” )
      End Sub

      Is this what your were look­ing for???

      Thanks
      Sumit

Leave a Reply

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

%d bloggers like this: