Consulting

Results 1 to 5 of 5

Thread: How to put multiple images in word file using macro?

  1. #1
    VBAX Newbie
    Joined
    Sep 2019
    Posts
    2
    Location

    How to put multiple images in word file using macro?

    I want to create a macro which help me to put multiple images in word file. brief is below

    1) The word document have tables
    2) The images are already patsed into the left side of the table in word file
    3) Just want to paste the images in the right side of the table in word file

    Please find the attachment i want to add images in the "ab" table in sequence.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oTbl As Table
    Dim lngIndex As Long
      For Each oTbl In ActiveDocument.Tables
        For lngIndex = 1 To oTbl.Rows.Count
          If oTbl.Cell(lngIndex, 1).Range.InlineShapes.Count > 0 Then
            oTbl.Cell(lngIndex, 1).Range.Cut
            oTbl.Cell(lngIndex, 2).Range.Paste
          End If
        Next
      Next
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Or you could do it using ranges, but somehow I get the impression it is a different set of images that need to be added, about which we know nothing.

    Sub Macro1()'Graham Mayor - https://www.gmayor.com - Last updated - 11 Sep 2019
    Dim oTable As Table
    Dim oRow As Row
    Dim oCell1 As Range, oCell2 As Range
        For Each oTable In ActiveDocument.Tables
            For Each oRow In oTable.Rows
                If oRow.Cells(1).Range.InlineShapes.Count > 0 Then
                    Set oCell1 = oRow.Cells(1).Range
                    oCell1.End = oCell1.End - 1
                    Set oCell2 = oRow.Cells(2).Range
                    oCell2.End = oCell2.End - 1
                    oCell2.FormattedText = oCell1.FormattedText
                    oCell1.Text = "" 'if you want to remove the image from the left cell
                End If
            Next oRow
        Next oTable
    lbl_Exit:
        Set oTable = Nothing
        Set oRow = Nothing
        Set oCell1 = Nothing
        Set oCell2 = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    VBAX Newbie
    Joined
    Sep 2019
    Posts
    2
    Location
    Thanks gmaxey and gmayor for the help and sorry for the confusion for my 3rd point.

    3) Just want to paste the images in the right side of the table in word file

    I want to paste the images in the right side of the table in the word file from the folder. so can you please help me to do that? Thanks in advance.




  5. #5
    You might consider https://www.gmayor.com/photo_gallery_template.html which has the option to create 1 column galleries with a caption column on the left, that doesn't have to have content
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •