Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 11-29-2022, 04:15 PM
Guessed's Avatar
Guessed Guessed is offline Insert multiple pictures at once in Word table Windows 10 Insert multiple pictures at once in Word table Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

At its most basic, assume your PNGs are all in the same folder as the Word document. Then this code will iterate through a column of text to add the corresponding image in the preceding cell
Code:
Sub InsertImages()
  Dim aCell As Cell, sPath As String, sFile As String, aTbl As Table, iCol As Integer
  Dim aRng As Range, aShp As InlineShape
  
  Set aTbl = Selection.Tables(1)
  iCol = Selection.Cells(1).Column.Index
  sPath = ActiveDocument.Path & Application.PathSeparator
  For Each aCell In aTbl.Columns(iCol).Cells
    sFile = sPath & Split(aCell.Range.Text, vbCr)(0) & ".png"
    If Len(Dir(sFile)) > 0 Then
      Debug.Print sFile
      Set aRng = aCell.Previous.Range
      Set aShp = ActiveDocument.InlineShapes.AddPicture(FileName:=sFile, Range:=aRng)
      aShp.AlternativeText = sFile
      aShp.Width = CentimetersToPoints(0.8)
      aShp.Height = CentimetersToPoints(0.8)
      aRng.Cells(1).VerticalAlignment = wdCellAlignVerticalCenter
      aRng.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    End If
  Next aCell
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert multiple pictures at once in Word table Mac - Macro insert pictures in table Nina Word VBA 16 08-27-2018 01:53 AM
Insert multiple pictures at once in Word table Macro to insert multiple pictures with adjustable column size nando88 Word VBA 6 05-09-2016 11:56 PM
Insert multiple pictures at once in Word table Insert an article with pictures into a table cell skatiemcb Word Tables 2 01-24-2015 08:18 AM
Insert multiple pictures at once in Word table Macro to insert multiple pictures to word to a specific size and text wrap mescaL Word VBA 3 11-03-2014 10:51 PM
Insert multiple pictures at once in Word table Resize multiple pictures in a Word 2010 table JBA479 Word VBA 1 01-24-2014 08:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft